i am using download manager for downloading a file. In order to show download progress i need file size. When i used the following code , I got file size as -1. How i get correct file size?
DownloadManager.Query q = new DownloadManager.Query();
q.setFilterById(downloadmanagerid1);
Cursor cursor = dm.query(q);
if (cursor.moveToFirst()) {
FileDownloading.setDownload_status(cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)));
long fileSize = cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
long bytesDL = cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
Log.e("file size getting ",""+fileSize);
FileDownloading.setDownload_progress((int) ((bytesDL * 100.0f) / fileSize));
}
else {
FileDownloading.setDownload_progress(0);
FileDownloading.setDownload_status(-1);
}
cursor.close();