一个用户发给我以下错误:
java.lang.IllegalArgumentException: Unknown URL content://downloads/my_downloads
at android.content.ContentResolver.insert(ContentResolver.java:860)
at android.app.DownloadManager.enqueue(DownloadManager.java:904)
at
,即使我使用以下代码:
ApplicationInfo ai = null;//Check if download manager is enabled
try {
ai = this.getPackageManager().getApplicationInfo("com.android.providers.downloads",0);
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
appStatus = ai.enabled;
当用户试图下载
if(appStatus=false){
// Download manager not available.....
}
else {
//filename=String
String fileName=URLUtil.guessFileName(url,contentDisposition,mimetype);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
request.setDescription(fileName);
manager.enqueue(request);
}
我做错了什么?
原因很简单:下载管理器被用户"停用"了。你可以这样做:进入设置>应用程序>所有应用程序,选择"下载管理器",然后点击"禁用"。
我在代码中检查它,像这样
try {
download.downloadManagerId = systemDownloadManager.enqueue(request)
download.state = DownloadState.DOWNLOADING
} catch (e:IllegalArgumentException) {
result.state = DownloadMagerResult.STATE.NOMANAGER
return result
}