why IllegalArgumentException happens in using DownloadManager?

586 views Asked by At

I used DownloadManager in my android project to download a file.

DownloadManager.Request request = new DownloadManager.Request(Uri.parse(soundURL));
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);
    deleteIfFileExist(filePath);
    request.setDestinationInExternalFilesDir(context, SubPath, SndName);
    return manager.enqueue(request);

it works fine but i saw in Fabric that some of users reported a crash:

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

I searched about it and found somewhere because their DownloadManger is disable. but I saw in android devices that android version is 4 they do not have ability to disable it. can anybody help me why this error happens?

1

There are 1 answers

0
UMESH0492 On

There is no way to activate/deactivate Download Manager directly, since it's system application and we don't have access to it.

Only alternative left is to redirect the User to the Info Page of Download Manager Application.

try {
     //Open the specific App Info page:
     Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
     intent.setData(Uri.parse("package:" + "com.android.providers.downloads"));
     startActivity(intent);

} catch ( ActivityNotFoundException e ) {
     e.printStackTrace();

     //Open the generic Apps page:
     Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS);
     startActivity(intent);
}