Android Download Manager not working on all phones

I'm learning to do Android application. I want to make a simple application. But I'm having a problem and I don't understand why. Download manager does not work on some android versions.When I press the download button in 4.1.1 version, the application stopping. In what versions does the download manager work?

My code

 DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
                                    request.setDescription(dlFilename);
                                    request.setTitle(dlFilename);

                                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                                        request.allowScanningByMediaScanner();
                                        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                                    }
                                    request.setDestinationInExternalPublicDir(downloadFolder, dlFilename);


                                    DownloadManager manager = (DownloadManager) getSystemService(MainActivity.this.DOWNLOAD_SERVICE);
                                    manager.enqueue(request);
                                    Toast.makeText(getApplicationContext(), MainActivity.this.getString(R.string.downloading), Toast.LENGTH_LONG).show();

manifest file

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />

LogCat

12-05 20:42:49.275 1510-1510/com.app.app/AndroidRuntime: FATAL EXCEPTION: main
                                                                            java.lang.IllegalStateException: Unable to create directory: /storage/emulated/0/media/ringtones
                                                                                at android.app.DownloadManager$Request.setDestinationInExternalPublicDir(DownloadManager.java:503)
                                                                                at com.app.MainActivity$1$4$2.onClick(MainActivity.java:409)
                                                                                at android.view.View.performClick(View.java:4204)
                                                                                at android.view.View$PerformClick.run(View.java:17355)
                                                                                at android.os.Handler.handleCallback(Handler.java:725)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:92)
                                                                                at android.os.Looper.loop(Looper.java:137)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5041)
                                                                                at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                at java.lang.reflect.Method.invoke(Method.java:511)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
                                                                                at dalvik.system.NativeStart.main(Native Method)

i am waiting for your help ... Thanks.

1 answer

  • answered 2018-12-05 20:53 Owen Selles

    DownloadManager only handles requests starting with http:// or https://