Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is my sdcard location on 4.4.2?

Tags:

android

On Android 4.4.2 Environment.getExternalStorageDirectory().getPath() returns /storage/emulated/0 but this path does not exist on my Nexus5 Android 4.4.2. Environment.getExternalStorageDirectory().getPath() worked up until Android 4.4.2.

How can I get the /sdcard path on Android 4.4.2?

like image 408
powder366 Avatar asked Dec 22 '13 22:12

powder366


People also ask

What is the path to the SD card on Android?

getExternalStorageDirectory() will return you the normal path for SD card which is mnt/sdcard/ . But for Samsung devices for example, the SD card path is either under mnt/extSdCard/ or under mnt/external_sd/ .

How to use sd card as internal storage on Android KitKat?

2 KitKat (NO ROOT)? Just go to Settings>>Apps then tap on the app you wish to move to the SD card and scroll down, if the app is in the phone memory; you will see an option “Move to SD Card”, tap it and your app will be moved to the SD card.


3 Answers

This path does not exist on my Nexus5 Android 4.4.2.

Yes, it does, for your process at runtime.

For example, this sample project downloads a file to Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS). If you log the location at runtime, when running it on a Nexus 5, it is reported as /storage/emulated/0/Download. And the download succeeds.

If you are looking for /storage/emulated/0 via DDMS or adb shell, you will not find it. For those tools, default external storage is /mnt/shell/emulated/0. Hence, the downloaded file from the above sample appears in the /mnt/shell/emulated/0/Download directory.

AFAIK, the difference is tied to providing separate external storage to secondary accounts.

like image 135
CommonsWare Avatar answered Oct 20 '22 12:10

CommonsWare


The Storage Options documentation says to use Environment.getExternalStorageDirectory() (as you are already correctly using). This function is available on all versions of Android.

Are you seeing it return a path that isn't actually available on a 4.2 device?

Please note (from Environment.getExternalStorageDirectory()):

Applications should not directly use this top-level directory, in order to avoid polluting the user's root namespace. Any files that are private to the application should be placed in a directory returned by Context.getExternalFilesDir, which the system will take care of deleting if the application is uninstalled. Other shared files should be placed in one of the directories returned by getExternalStoragePublicDirectory(String).

Writing to this path requires the WRITE_EXTERNAL_STORAGE permission, and starting in read access requires the READ_EXTERNAL_STORAGE permission, which is automatically granted if you hold the write permission.

Starting in KITKAT, if your application only needs to store internal data, consider using getExternalFilesDir(String) or getExternalCacheDir(), which require no permissions to read or write.

like image 24
NPike Avatar answered Oct 20 '22 13:10

NPike


Sometimes /storage/emulated/0 can be written to, but reads fail... so tests for "writability" are not sufficient. This is such an annoying problem, I have come up with an equally annoying but effective solution. Hardcode "/mnt/sdcard" Yea, I said it.

Looks like someone else said it first ... storing android application data on SD Card

More joy... http://forums.bignerdranch.com/viewtopic.php?f=414&t=7407

like image 31
kandinski Avatar answered Oct 20 '22 12:10

kandinski