我无法在上述设备中使用DownloadManager下载文件。相同的代码适用于所有其他设备。 问题是为什么它不能只在这个设备上工作。如果这是三星特定的问题,是否有解决方法?我已经尝试更改下载应该发生但不起作用的目录。
Android操作系统:4.1.2
崩溃日志:
09-24 15:48:34.298: E/ActivityThread(19843): Failed to find provider info for downloads
09-24 15:48:34.306: D/AndroidRuntime(19843): Shutting down VM
09-24 15:48:34.337: E/AndroidRuntime(19843): FATAL EXCEPTION: main
09-24 15:48:34.337: E/AndroidRuntime(19843): java.lang.IllegalArgumentException: Unknown URL content://downloads/my_downloads
09-24 15:48:34.337: E/AndroidRuntime(19843): at android.content.ContentResolver.insert(ContentResolver.java:860)
09-24 15:48:34.337: E/AndroidRuntime(19843): at android.app.DownloadManager.enqueue(DownloadManager.java:1252)
09-24 15:48:34.337: E/AndroidRuntime(19843): at com.example.ws.appcatalog.exampleDownloadManager.startDownload(exampleDownloadManager.java:59)
09-24 15:48:34.337: E/AndroidRuntime(19843): at com.example.ws.wsUtil$GetEulaOrApkUrlTask.onPostExecute(wsUtil.java:340)
09-24 15:48:34.337: E/AndroidRuntime(19843): at com.example.ws.wsUtil$GetEulaOrApkUrlTask.onPostExecute(wsUtil.java:1)
09-24 15:48:34.337: E/AndroidRuntime(19843): at android.os.AsyncTask.finish(AsyncTask.java:631)
09-24 15:48:34.337: E/AndroidRuntime(19843): at android.os.AsyncTask.access$600(AsyncTask.java:177)
09-24 15:48:34.337: E/AndroidRuntime(19843): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
09-24 15:48:34.337: E/AndroidRuntime(19843): at android.os.Handler.dispatchMessage(Handler.java:99)
09-24 15:48:34.337: E/AndroidRuntime(19843): at android.os.Looper.loop(Looper.java:137)
09-24 15:48:34.337: E/AndroidRuntime(19843): at android.app.ActivityThread.main(ActivityThread.java:4895)
09-24 15:48:34.337: E/AndroidRuntime(19843): at java.lang.reflect.Method.invokeNative(Native Method)
09-24 15:48:34.337: E/AndroidRuntime(19843): at java.lang.reflect.Method.invoke(Method.java:511)
09-24 15:48:34.337: E/AndroidRuntime(19843): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
09-24 15:48:34.337: E/AndroidRuntime(19843): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
09-24 15:48:34.337: E/AndroidRuntime(19843): at dalvik.system.NativeStart.main(Native Method)
我的代码:
public void startDownload(String apkUrl, String appName){
DownloadManager.Request request = buildRequest(apkUrl, appName);
long lastDownloadId = mDownloadManager.enqueue(request);
Logger.d("In XYZDownloadManager, " + "AppName: " + appName + " with ID: " + lastDownloadId);
}
private DownloadManager.Request buildRequest(String apkUrl, String appName){
Uri uri = Uri.parse(apkUrl);
DownloadManager.Request appDownloadRequest = new DownloadManager.Request(uri);
appDownloadRequest.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI
| DownloadManager.Request.NETWORK_MOBILE)
.setAllowedOverRoaming(false)
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)
.setTitle(appName)
.setDescription(WorkspaceApp.getAppContext().getResources().getString(R.string.app_download_description))
.setMimeType("application/vnd.android.package-archive")
.setDestinationInExternalFilesDir(mContext, Environment.DIRECTORY_DOWNLOADS, appName + ".apk");
return appDownloadRequest;
}
答案 0 :(得分:8)
问题是:设备已禁用DownloadManager应用。充其量,IMO,我们可以做的是通知用户当我们排队下载并且如果他想要再次启用它时我们获得IllegalArgument Exception时设备已禁用下载管理器。