• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Alternative of Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS) deprecated code?

Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS).
This is a deprecated code in api>29 and I want to get some alternative of that Which returns the address of common download folder of all application(storage/emulated/0/Downloads) Not the location of download folder of inside android app location(storage/emulated/0/Android/data/__AndroidPackageName__/Downloads)
 
To get the path to the shared download directory on Android devices running API level 29 and higher, you can use the getExternalFilesDir method of the Context class and pass it the DIRECTORY_DOWNLOADS constant.

Here is an example of how you can use it:
Code:
val downloadDirectory = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)

This will return the path to the shared download directory, which is typically located at /storage/emulated/0/Downloads.

If you need to access the download directory of your app's private files, you can use the getExternalFilesDir method without any arguments. This will return the path to your app's private download directory, which is typically located at /storage/emulated/0/Android/data/<package_name>/files/Download.

Note that the getExternalStoragePublicDirectory method has been deprecated in API level 29 and is no longer recommended for use.
 
it doesn't work I tried with java by using getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS) but the file is stored in the /storage/emulated/0/Android/data/<package_name>/files/Download directory
 
Back
Top Bottom