android – 为什么在使用DownloadManager时会发生IllegalArgumentException?

我在我的 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,他们没有能力禁用它.任何人都可以帮助我为什么会发生这种错误

解决方法

无法直接激活/停用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);
}

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...