我在我的 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/