Why does IllegalArgumentException occur when using DownloadManager?

I used DownloadManagerin my Android project to upload 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 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 they are DownloadMangerdisabled. but I saw on Android devices that the version for Android is 4, they don’t have the ability to disable it. can someone help me why this error is happening?

+4
source share
1 answer

It is not possible to activate / deactivate the Download Manager directly, as it is a system application and we do not have access to it.

- Info Download Manager.

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);
}
0

Source: https://habr.com/ru/post/1664167/


All Articles