I need to get the path of the internal Downloads directory.
Things I have tried:
val home = System.getProperty("user.home")
val downloadsDirectory = File("$home/Downloads"
val downloadsDirectory = File("/storage/emulated/0/Download")
System.getProperty("user.home") just returns an empty string.
I also tried
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
and it returned this path /storage/emulated/0/Download but then the downloadsDirectory.listFiles() method returns null, although I have a file in the directory.
On Android 9 and below, use Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).
On Android 10 and higher, stop thinking in terms of files. Instead, switch to the Storage Access Framework or, for limited scenarios, use MediaStore.Downloads.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With