Android Download Manager Issue in Samsung Tab GT-P3100

为君一笑 提交于 2019-12-06 06:29:06

问题


I am not able to download files using DownloadManager in the aforementioned device. The same code works for all other devices. The question is why is it not working only in this device. If it's a Samsung specific issue, is there a workaround for this? I have tried changing directories to which the download should happen but that didn't work either.

Android OS: 4.1.2

Crash Logs:

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)

My Code:

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;
}

回答1:


The issue was: the device had DownloadManager app disabled. At best, IMO, what we can do is notify user that the device has Download Manager disabled when we get IllegalArgument Exception when we enqueue a download and if he would want to enable it again.



来源:https://stackoverflow.com/questions/18979160/android-download-manager-issue-in-samsung-tab-gt-p3100

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!