0

One user sent me the following error:

java.lang.IllegalArgumentException: Unknown URL content://downloads/my_downloads
at android.content.ContentResolver.insert(ContentResolver.java:860)
at android.app.DownloadManager.enqueue(DownloadManager.java:904)
at 

even if i use the following code:

ApplicationInfo ai = null;//Check if download manager is enabled
        try {
            ai = this.getPackageManager().getApplicationInfo("com.android.providers.downloads",0);
        } catch (NameNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

         appStatus = ai.enabled;

When user tries to download

                if(appStatus=false){
                        //  Download manager not available.....
                    }           
                    else {
    //filename=String
    String fileName=URLUtil.guessFileName(url,contentDisposition,mimetype); 

request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
                    request.setDescription(fileName);      
                    manager.enqueue(request); 
                    }

What i am doing wrong?

Device
  • 993
  • 3
  • 11
  • 26

1 Answers1

0

The reason is simple: The Download Manger is "deactivated" from the user. You can do this by going into Settings > Apps > All Apps, and picking "Download Manager" then tapping "Disable".

I use to check it in my code like this

    try {
        download.downloadManagerId = systemDownloadManager.enqueue(request)
        download.state = DownloadState.DOWNLOADING
    } catch (e:IllegalArgumentException) {
        result.state = DownloadMagerResult.STATE.NOMANAGER
        return result
    }
Mate
  • 418
  • 3
  • 13