Skip to content

Instantly share code, notes, and snippets.

@granoeste
Last active November 4, 2024 06:16
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
@angelaburova
Copy link

I don't know how i can getting

Environment.getExternalStorageDirectory() /storage/sdcard0

I get /storage/emulated/0
:(

@felipeslongo
Copy link

Excelent.

Thank you very much for this.

@Skywalker97
Copy link

Thanks a ton for this. :)

@casaurabhkhatri
Copy link

thankssssssss

@damionx7
Copy link

damionx7 commented Jul 8, 2018

Thanks

@1nsp1r3rnzt
Copy link

Thanks. Its really helpful.

@harshit-khandelwal-1
Copy link

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

@nickfl
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"!?

@aznj
Copy link

aznj commented Aug 28, 2019

most of are deprecated

@latifdev535
Copy link

yes, most of them are depre..!

@arturoguillen90
Copy link

Excelent ...

@FitApps7
Copy link

thanks

@granoeste
Copy link
Author

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

@rzakfirst
Copy link

How get res/raw directory?

@vaishnavmhetre
Copy link

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

@Suret1
Copy link

Suret1 commented Mar 2, 2021

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

@droidchief
Copy link

I tried to specify a destination for my download manager`

private fun downloadVideos() {
var request = DownloadManager.Request(Uri.parse("https://images.unsplash.com/photo-1558981408-db"))
.setTitle("Phonics")
.setDescription("Downloading phonics level one")
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)
.setAllowedOverMetered(true)
.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.

@sushantj651
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