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

Viewed 1224

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.

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.

Related