Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[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
@edwardstock

This comment has been minimized.

Copy link

@edwardstock edwardstock commented Oct 27, 2014

that's what i need! Thanks!

@granoeste

This comment has been minimized.

Copy link
Owner Author

@granoeste granoeste commented Jun 25, 2015

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

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

@lakeman

This comment has been minimized.

Copy link

@lakeman 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.

https://source.android.com/devices/storage/

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

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

@jankrav

This comment has been minimized.

Copy link

@jankrav jankrav commented Jan 28, 2017

cool, thank you man!

@dropoutninja

This comment has been minimized.

Copy link

@dropoutninja dropoutninja commented Jun 22, 2017

thanks dude

@BruceleeThanh

This comment has been minimized.

Copy link

@BruceleeThanh BruceleeThanh commented Sep 28, 2017

thank bro, very helpful 👍

@angelaburova

This comment has been minimized.

Copy link

@angelaburova angelaburova commented Jan 15, 2018

I don't know how i can getting

Environment.getExternalStorageDirectory() /storage/sdcard0

I get /storage/emulated/0
:(

@felipeslongo

This comment has been minimized.

Copy link

@felipeslongo felipeslongo commented Mar 10, 2018

Excelent.

Thank you very much for this.

@Skywalker97

This comment has been minimized.

Copy link

@Skywalker97 Skywalker97 commented Mar 12, 2018

Thanks a ton for this. :)

@casaurabhkhatri

This comment has been minimized.

Copy link

@casaurabhkhatri casaurabhkhatri commented May 5, 2018

thankssssssss

@damionx7

This comment has been minimized.

Copy link

@damionx7 damionx7 commented Jul 8, 2018

Thanks

@1nsp1r3rnzt

This comment has been minimized.

Copy link

@1nsp1r3rnzt 1nsp1r3rnzt commented Aug 2, 2018

Thanks. Its really helpful.

@Harshit20051

This comment has been minimized.

Copy link

@Harshit20051 Harshit20051 commented Aug 16, 2018

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

@nickfl

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

@aznj aznj commented Aug 28, 2019

most of are deprecated

@latifdev535

This comment has been minimized.

Copy link

@latifdev535 latifdev535 commented Dec 24, 2019

yes, most of them are depre..!

@arturoguillen90

This comment has been minimized.

Copy link

@arturoguillen90 arturoguillen90 commented Jan 8, 2020

Excelent ...

@FitApps7

This comment has been minimized.

Copy link

@FitApps7 FitApps7 commented Jan 22, 2020

thanks

@granoeste

This comment has been minimized.

Copy link
Owner Author

@granoeste granoeste commented May 15, 2020

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

@rzakfirst

This comment has been minimized.

Copy link

@rzakfirst rzakfirst commented Jun 20, 2020

How get res/raw directory?

@vaishnavmhetre

This comment has been minimized.

Copy link

@vaishnavmhetre vaishnavmhetre commented Jan 9, 2021

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

@Suret1

This comment has been minimized.

Copy link

@Suret1 Suret1 commented Mar 2, 2021

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

@Vicviral

This comment has been minimized.

Copy link

@Vicviral Vicviral commented Mar 24, 2021

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

This comment has been minimized.

Copy link

@sushantj651 sushantj651 commented Apr 15, 2021

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