Hi in my android application i need to download media files from server, for that i have used Download Manager service. And also i want to show the progress of the download in ui. Downloading works perfectly but progress bar is updating only when status becomes STATUS_SUCCESSFUL. I have used the following code for finding the percentage of downloaded data,
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 have noticed that the value of bytes_total remain -1 during status STATUS_RUNNING, it is only fills up when download finishes. So how can i update the progressbar with this calculation. please help...