I Want To Download And save file from my url to external storage download directory in Android 10. I have used this code to download.
public void StartNewDownload(String url) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setDescription("Downloading Profile");
request.setTitle("Abc App");
request.setDestinationInExternalPublicDir(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+ File.separator, "parag.jpeg");
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
final long downloadId = manager.enqueue(request);
}
it shows error
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.abc, PID: 15197
java.lang.IllegalStateException: Not one of standard directories: /storage/emulated/0/Download/ at android.os.Parcel.createException(Parcel.java:2079) at android.os.Parcel.readException(Parcel.java:2039) at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:188) at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140) at android.content.ContentProviderProxy.call(ContentProviderNative.java:658) at android.content.ContentProviderClient.call(ContentProviderClient.java:558) at android.content.ContentProviderClient.call(ContentProviderClient.java:546) at android.app.DownloadManager$Request.setDestinationInExternalPublicDir(DownloadManager.java:569) at com.example.abc.Activity.showDetails.StartNewDownload(showDetails.java:102) at com.example.abc.Activity.showDetails$1.onClick(showDetails.java:68)
But if i use
request.setDestinationInExternalFilesDir(this,Environment.DIRECTORY_DOWNLOADS+ File.separator , "parag.jpeg");
this downloads the file but in my app specific folder but i want to download the file in external public download directory