Android download manager.COLUMN_TOTAL_SIZE_BYTES returns -1 during status execution

Hello in my android app. I need to download media from the server because I used the Download Manager service. And also I want to show the loading progress in the ui. The download works fine, but the progress bar only refreshes when the status becomes STATUS_SUCCESSFUL. I used the following code to find the percentage of data loaded,

DownloadManager.Query q = new DownloadManager.Query();
                q.setFilterById(enqueue);
                Cursor cursor = dm.query(q);
                cursor.moveToFirst();
int bytes_downloaded = cursor.getInt(cursor                      .getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
int bytes_total = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));    
final long dl_progress = (bytes_downloaded*100L)/bytes_total;

      

I noticed that the bytes_total value stays at -1 during the STATUS_RUNNING state, it fills up only when the download is complete. So how can I update the progressbar with this calculation. please, help...

+3


source to share


1 answer


This may be due to the server not supporting HTTP HEAD or OPTION calls. I had a similar problem when I tried this with Simple Python server where I got the value for COLUMN_TOTAL_SIZE_BYTES as -1. But when I tried using apache tomcat this problem was solved.



This is most likely due to the server not sending the required metadata. If you are trying to do this with an Android emulator, you can check it using Wireshark or any other packet monitoring software to see if the server supports my Android Download Manager network call.

0


source







All Articles