0

Writing exception to parcel java.lang.IllegalStateException: Not one of standard directories: /storage/emulated/0/Android/data...............

 DownloadManager dm = (DownloadManager) context.getSystemService(DOWNLOAD_SERVICE);
                    Uri uri = Uri.parse(s);
                    DownloadManager.Request req = new DownloadManager.Request(uri);
                    req.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                    String filename = VideoTitle;
                    filename += ".mp4";

                    req.setDestinationInExternalPublicDir(context.getResources().getString(R.string.video_dir_path), filename);
                    req.setDestinationInExternalFilesDir(context,dir_path,filename);
                    StyleableToast.makeText(context,context.getResources().getString(R.string.download_started), Toast.LENGTH_SHORT, R.style.mytoast).show();

                    Long ref = dm.enqueue(req);

How to resolve this error??

1 Answers1

0

I believe the problem is in the line you mentioned. The concatenation you're setting up is changing the directory of the file to one that is not standard.

For Eg:

request.setDestinationInExternalPublicDir(getExternalFilesDir(Environment.DIRECTORY_PICTURES) + "/NewFile","abc.jpg")

The error shows that. See that the line tells you which directory it is trying to save to

Something like this

/storage/emulated/0/Android/data/com.a.b.downloadmanager/files/Pictures/NewFile

So when you do that, it will try to save as

/storage/emulated/0/Android/data/com.a.b.downloadmanager/files/Pictures/NewFile/abc.jpg

A solution to this would be to save the file to the standard directory. To do so you would only need to remove the concatenation.

Eg:

request.setDestinationInExternalPublicDir(getExternalFilesDir(Environment.DIRECTORY_PICTURES),"abc.jpg")

Then it will try to save to the standard directory

/storage/emulated/0/Android/data/com.a.b.downloadmanager/files/Pictures/abc.jpg

and Make sure you have

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

Make sure you have

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

in your manifest.xml

Also if you are using an emulator, make sure you created it with SD card storage. It's NOT created by default.

Kiran Mistry
  • 2,614
  • 3
  • 12
  • 28
  • I tried but **DownloadManager** not working for Android **Vivo 1812** **version 8.1.0** – Muhammad Asif Javed Feb 19 '20 at 07:07
  • check this [link](https://stackoverflow.com/questions/37082354/download-manager-not-working) and example is [here](http://www.worldbestlearningcenter.com/tips/Android-DownloadManager-example.htm#) – Kiran Mistry Feb 19 '20 at 09:19