Skip to content

Instantly share code, notes, and snippets.

Last active July 23, 2024 09:11
Show Gist options
  • Save granoeste/5574148 to your computer and use it in GitHub Desktop.
Save granoeste/5574148 to your computer and use it in GitHub Desktop.
[Android] How to get the each directory path.

System directories

Method Result
Environment.getDataDirectory() /data
Environment.getDownloadCacheDirectory() /cache
Environment.getRootDirectory() /system

External storage directories

Method Result
Environment.getExternalStorageDirectory() /storage/sdcard0
Environment.getExternalStoragePublicDirectory(DIRECTORY_ALARMS) /storage/sdcard0/Alarms
Environment.getExternalStoragePublicDirectory(DIRECTORY_DCIM) /storage/sdcard0/DCIM
Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS) /storage/sdcard0/Download
Environment.getExternalStoragePublicDirectory(DIRECTORY_MOVIES) /storage/sdcard0/Movies
Environment.getExternalStoragePublicDirectory(DIRECTORY_MUSIC) /storage/sdcard0/Music
Environment.getExternalStoragePublicDirectory(DIRECTORY_NOTIFICATIONS) /storage/sdcard0/Notifications
Environment.getExternalStoragePublicDirectory(DIRECTORY_PICTURES) /storage/sdcard0/Pictures
Environment.getExternalStoragePublicDirectory(DIRECTORY_PODCASTS) /storage/sdcard0/Podcasts
Environment.getExternalStoragePublicDirectory(DIRECTORY_RINGTONES) /storage/sdcard0/Ringtones

Application directories

Method Result
getCacheDir() /data/data/package/cache
getFilesDir() /data/data/package/files
getFilesDir().getParent() /data/data/package

Application External storage directories

Method Result
getExternalCacheDir() /storage/sdcard0/Android/data/package/cache
getExternalFilesDir(null) /storage/sdcard0/Android/data/package/files
getExternalFilesDir(DIRECTORY_ALARMS) /storage/sdcard0/Android/data/package/files/Alarms
getExternalFilesDir(DIRECTORY_DCIM) /storage/sdcard0/Android/data/package/files/DCIM
getExternalFilesDir(DIRECTORY_DOWNLOADS) /storage/sdcard0/Android/data/package/files/Download
getExternalFilesDir(DIRECTORY_MOVIES) /storage/sdcard0/Android/data/package/files/Movies
getExternalFilesDir(DIRECTORY_MUSIC) /storage/sdcard0/Android/data/package/files/Music
getExternalFilesDir(DIRECTORY_NOTIFICATIONS) /storage/sdcard0/Android/data/package/files/Notifications
getExternalFilesDir(DIRECTORY_PICTURES) /storage/sdcard0/Android/data/package/files/Pictures
getExternalFilesDir(DIRECTORY_PODCASTS) /storage/sdcard0/Android/data/package/files/Podcasts
getExternalFilesDir(DIRECTORY_RINGTONES) /storage/sdcard0/Android/data/package/files/Ringtones
Copy link

that's what i need! Thanks!

Copy link

WTF! Galaxy S6

Environment.getExternalStoragePublicDirectory(DIRECTORY_MOVIES) returns "/storage/emulated/0/Movies" on Galaxy S6 (SC-04G 5.0.2)

$ adb shell ls /storage/emulated/0/Movies
/storage/emulated/0/Movies: No such file or directory

$ adb shell ls -l /storage/emulated
lrwxrwxrwx root     root              2015-06-25 15:01 legacy -> /mnt/shell/emulated/0

$ adb shell mkdir /storage/emulated/0/Movies
mkdir failed for /storage/emulated/0/Movies, No such file or directory

Exception when calling MediaPlayer.setDataSource(FileDescriptor) method (failed.: status=0x80000000)

Copy link

lakeman commented Jan 18, 2016

Since android added multi-user support, the sdcard is a really weird beast as permissions aren't mapped cleanly to linux users & groups.

... synthesized permissions are accomplished by wrapping raw storage devices in a FUSE daemon

Which can lead to unexpected permission errors for the shell user.

Copy link

jankrav commented Jan 28, 2017

cool, thank you man!

Copy link

thanks dude

Copy link

thank bro, very helpful 👍

Copy link

I don't know how i can getting

Environment.getExternalStorageDirectory() /storage/sdcard0

I get /storage/emulated/0

Copy link


Thank you very much for this.

Copy link

Thanks a ton for this. :)

Copy link


Copy link

damionx7 commented Jul 8, 2018


Copy link

Thanks. Its really helpful.

Copy link

In my Moto G(5s)
the method Environment.getDownloadCacheDirectory() returns /data/cache which already comes under /data
what to do about this?

Copy link

nickfl commented Sep 21, 2018

Just my two cents:
On my Nexus 6 I have "Downloads" (plural), but DIRECTORY_DOWNLOADS points to "Download" (single)!
The docs say "for backwards compatibility reasons"!?

Copy link

aznj commented Aug 28, 2019

most of are deprecated

Copy link

yes, most of them are depre..!

Copy link

Excelent ...

Copy link


Copy link

The directory name and mount path may differ due to the device implementation. 😄

Copy link

How get res/raw directory?

Copy link

Which is accessible way to get /storage/emulated/0 in Flutter. Coz by default it is calling getExternalFilesDir internally!!

Copy link

Suret1 commented Mar 2, 2021

Environment.getExternalStorageDirectory() not working in Android 11. is there any way suggestion?

Copy link

I tried to specify a destination for my download manager`

private fun downloadVideos() {
var request = DownloadManager.Request(Uri.parse(""))
.setDescription("Downloading phonics level one")
.setDestinationInExternalPublicDir("test.mp4", "Allon Fasaha/Module 1/Literacy/Level 1/Phonics/")

    var dm = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
    myDownloadID = dm.enqueue(request)


Still not downloading at the specified path.

Copy link

Is every android device internal storage start with "storage/emulated/0/" path? Or have some android devices it will be differ??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment