3

我无法在上述设备中使用 DownloadManager 下载文件。相同的代码适用于所有其他设备。问题是为什么它不能只在这个设备上工作。如果这是三星特有的问题,是否有解决方法?我已经尝试更改应该进行下载的目录,但这也不起作用。

安卓操作系统: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;
}
4

1 回答 1

8

问题是:设备禁用了 DownloadManager 应用程序。充其量,IMO,我们能做的就是通知用户,当我们将下载排入队列时收到 IllegalArgument 异常,并且他想再次启用它时,设备已禁用下载管理器。

于 2013-09-24T12:59:01.050 回答