2

When i'm trying to run the following code on my nexus 5 it shows a progress bar and actually download the file.

DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
                    request.setDescription("");
                    request.setTitle("");
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                        request.allowScanningByMediaScanner();
                        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                    }


                    DownloadManager manager = (DownloadManager) getSystemService(Environment.DIRECTORY_MUSIC);
                    manager.enqueue(request);
                }

but when i try the same thing on a lg g2 or lg g3 the file doesn't even start download and i get this message right after the beginning. on lg devides

I think the problem is that lg phones have a different music dir and Environment.DIRECTORY_MUSIC gives me an empty dir. If that is the problem does anyone know a way to get a correct dir for all devices? and if not does anyone have a clue what is the problem and how do i get it fixed?

ben
  • 1,064
  • 3
  • 15
  • 29
  • I have the same issue. But this notification can appear at the random moment of time after download was started – Nisazh Jan 17 '17 at 08:50

1 Answers1

0

It looks like you are passing a bad name into the getSystemService() call:

(DownloadManager) getSystemService( Environment.DIRECTORY_MUSIC );

Should be something like:

(DownloadManager) getSystemService( DOWNLOAD_SERVICE );
Adam
  • 25,966
  • 23
  • 76
  • 87