3

I'm trying to download pdf file, via DownloadManager.

Here is method to handle it:

public static final String MIME_TYPE_PDF = "application/pdf";

public static void downloadData(String url, Activity activity, String fileName, String mimeType) {

    if (hasPermissions(activity)) {

        DownloadManager manager = (DownloadManager) activity.getSystemService(Context.DOWNLOAD_SERVICE);

        DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));

        request.setTitle(fileName);
        request.setMimeType(mimeType);
        request.allowScanningByMediaScanner();
        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
        request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);

        manager.enqueue(request);
    } else {
        ActivityCompat.requestPermissions(activity, writePermission, Consts.WRITE_EXTERNAL_REQUEST_CODE);
    }
}

This code works perfectly on my HTC M9 with Android M on it. But when I test my app on older HTC - with android 4.4 on it, app starts to download the file, but it stucks on "queued" mode. I mean, the file drops in Downloads direction and its status is "queued". After several seconds, download manager tries to download it again, but goes in "queued" status again. After several attempts, its status goes to "unsuccessful".

On both devices, download url is same and it is correct (otherwise file shouldn't be downloaded on either device).

I couldn't figure out why this code works on some devices and not on others. Can anyone help?

Here is downloadmanager logs:

04-18 17:41:05.329 13502-13529/? D/DownloadManager: checkFileUriDestination : valid path 
04-18 17:41:09.339 13502-17179/? D/DownloadManager: [4263] Starting  app
04-18 17:41:09.369 13502-17179/? W/DownloadManager: [4263] Stop requested with status HTTP_DATA_ERROR: "link here"
04-18 17:41:09.369 13502-17179/? D/DownloadManager: [4263] Finished with status WAITING_TO_RETRY
04-18 17:41:09.369 13502-17179/? V/DownloadManager: MIME Type = application/pdf
04-18 17:41:09.429 13502-17179/? I/DownloadManager: Download 4263 finished with status WAITING_TO_RETRY

p.s. url starts with "https" - can be this a case? if yes, what is solution?

thank you in advance

Giorgi Margiani
  • 215
  • 4
  • 12

0 Answers0