majidgolshadi / Android-Download-Manager-Pro

Android/Java download manager library help you to download files in parallel mechanism in some chunks.
MIT License
1.62k stars 317 forks source link

getting progress percentage using ReportStruct #12

Open bkjbkjbnkj687698698 opened 9 years ago

bkjbkjbnkj687698698 commented 9 years ago

I want to get the status of downloaded file while its downloading.For that I am using ReportStruct.But both report.getTotalSize() and report.toJsonObject().get("percent") is returning 0 even if i place report.toJsonObject().get("percent") inside onDownloadProcess.How can i get the percentage progress of downloaded video?

   int taskToekn = dm.addTask(caption, url, false, false);
    try {

            dm.startDownload(taskToekn);

        } catch (Exception e) {

            e.printStackTrace();
        }

        ReportStructure report = dm.singleDownloadStatus(taskToekn);
        Log.e("BHUV", "totalsize" + report.getTotalSize());
  try {
            Log.e("Bhuv", "percent" + report.toJsonObject().get("percent"));
        } catch (JSONException e) {
            e.printStackTrace();
        }

Both Logs return 0 and 0.0

majidgolshadi commented 9 years ago

You use these methods in a wrong way As you can see onDownloadProcess method gave you percentage and downloaded file size. You can use them instead of your way.

jhony112 commented 9 years ago

Majid awesome library here..but please could you write a code snippet of what u mean? I am having same problem..