3

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;
}
Raptor
  • 53,206
  • 45
  • 230
  • 366
Nitin Sethi
  • 1,416
  • 1
  • 11
  • 19
  • 2
    Is that happening with one particular device or with all (several) GT-P3100's? – ozbek Sep 24 '13 at 10:53
  • Agreed, unless demonstrated otherwise, I would assume this a flawed ROM mod running your app. The error indicates that the Downloads app and its `ContentProvider` do not exist on the device. – CommonsWare Sep 24 '13 at 11:30
  • Strangely it's working in the other GT-P3100 we have. – Nitin Sethi Sep 24 '13 at 11:31
  • If the exception is not happening in all devices, could the problem related with using `Environment.DIRECTORY_DOWNLOADS`? Maybe user has deleted `/sdCard/Download` folder or it has became inaccessibly by other means? – ozbek Sep 24 '13 at 12:35

1 Answers1

8

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.

Nitin Sethi
  • 1,416
  • 1
  • 11
  • 19
  • Alternatively, you can check DownloadManager's enabled state (`PackageManager.getComponentEnabledSetting()`?) and get killed by `IllegalArgumentException` caused by other means and be able to address them properly :) – ozbek Sep 24 '13 at 13:18
  • I get Exception in only one particular line: long lastDownloadId = mDownloadManager.enqueue(request); What other exception I might get in that one line which I should be wary about? – Nitin Sethi Sep 24 '13 at 16:25
  • 1
    I don't know, maybe there is none other. I was just implying that it is, generally, better not to catch exceptions and let the "bugs" be visible. – ozbek Sep 24 '13 at 17:02