ap s ap s - 1 month ago 28
Android Question

Unable to create directory: /sdcard/Downloads

I am using DownloadManager class to download file and save it.

DownloadManager.Request request = new DownloadManager.Request(uri);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,"logo.jpg");


I am getting "java.lang.IllegalStateException: Unable to create directory: /sdcard/Download" runtime exception.

I have searched all the possible solutions and not able to get the answer.

Below is the full stack tracel .

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.architsandesara.myapplication, PID: 24246
java.lang.IllegalStateException: Unable to create directory: /sdcard/Download
at android.app.DownloadManager$Request.setDestinationInExternalPublicDir(DownloadManager.java:538)
at com.example.architsandesara.myapplication.fragment.DocumentsDetails$2.onClick(DocumentsDetails.java:91)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Answer

secondary storages (like the real removable SD card) are protected by a new permission android.permission.WRITE_MEDIA_STORAGE, and the protection level is signatureOrSystem. one of the answers at stack overflow suggests this.

check this answer aswell.

Comments