Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the path of the internal Downloads directory in Android?

Tags:

android

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.

like image 944
Dinu Nicolae Avatar asked Nov 16 '25 22:11

Dinu Nicolae


1 Answers

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.

like image 120
CommonsWare Avatar answered Nov 18 '25 13:11

CommonsWare