android - 为什么在使用 DownloadManager 时会出现 IllegalArgumentException?

标签 android android-download-manager

我在我的 android 项目中使用了 DownloadManager 来下载一个文件。

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

它工作正常,但我在 Fabric 中看到一些用户报告崩溃:

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)

我搜索了一下并找到了某个地方,因为他们的 DownloadManger 被禁用了。但我在 android 设备中看到 android 版本是 4,他们没有能力禁用它。谁能帮我解释为什么会发生这个错误?

最佳答案

无法直接激活/停用下载管理器,因为它是系统应用程序,我们无权访问它。

剩下的唯一选择是将用户重定向到下载管理器应用程序的信息页面。

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

关于android - 为什么在使用 DownloadManager 时会出现 IllegalArgumentException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41222923/

相关文章:

android - 如何解决DownloadManager无法打开文件和文件丢失的问题?

Android CameraX GLSurfaceView

Android 多 WebViews 问题 : Not being able to load the first one until the rest have loaded

android - 如何在 Android Pie 中使用蓝牙 HID 设备配置文件?

java - 如何在android上将SQLiteDatabase查询结果显示为html?

java - android studio ExpandableListAdapter 上下文错误

android - 为什么 "download completed"通知在 Gingerbread 设备上消失了?

android - 使用下载管理器下载 zip 文件

java - Android:从 "Downloads"文件夹中删除下载的文件快捷方式

java - 即使应用程序终止,如何在后台使用下载管理器下载多个文件?