Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: absolute location of External sd-card

I have a very simple question but so far I am unable to find an answer of this question. "Is there any way of finding the absolute path of INTERNAL STORAGE DIRECTORY and EXTERNAL STORAGE DIRECTORY(SDCARD) in Android?"

Please don't recommend using Environment.getExternalStorageDirectory since it usually returns the path for internal storage or WHATEVER storage media is selected as default by the Android operating system..

Any suggestions please?

like image 360
Farhan Avatar asked Aug 31 '11 01:08

Farhan


People also ask

What is the path to my 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 do I force my Android to use SD card as internal storage?

Step 1: Go to device “Settings” and select “Storage”. Step 2: Select your "SD Card", then tap the “three-dot menu“ (top-right), now select “Settings” from in there. Step 3: Now select “Format as internal”, and then “Erase & Format”. Step 4: Your SD Card will now be formatted as internal storage.


4 Answers

That's been asked before on SO, use the search. In short, 'external storage' is more like 'shared storage' and it may or may not be implemented by an actual SD card. Some devices have an additional SD card, not used as external storage. If that is what you are asking for, there is currently no public API for accessing its mount location, and it varies between devices. You can check /proc/mount to see what is currently mounted and go from there.

like image 174
Nikolay Elenkov Avatar answered Sep 27 '22 17:09

Nikolay Elenkov


This link is from the Android configuration guide. I assume it's recommend and is not required.

https://source.android.com/devices/tech/storage/config-example.html

So, to get the SDCARD, you can just do.

String storagePath = System.getenv("SECONDARY_STORAGE");

if (storagePath == null) {
    return null;
} else {
     String[] storagePathArray = storagePath.split(":");
     return storagePathArray[0];
}

EXTERNAL_STORAGE seems to be on everything on I own.

SECONDARY_STORAGE was defined on my LG GTab 8.3 and my Samsung Tab 2&3, but not on my Galaxy S (2.3) or my Dell Venue (4.3). On Samsung devices it seems to contained multiple paths with the SD card first, thus the split.

like image 44
Dustin Avatar answered Sep 27 '22 17:09

Dustin


You should use

Environment.getExternalStorageDirectory().getAbsolutePath()
like image 20
basicsharp Avatar answered Sep 27 '22 18:09

basicsharp


On Samsung Galaxy Note 10.1 2014 edition SM-P600 (and I would assume most other samsung galaxy notes of the same vintage), the full path to the "REAL" external sdcard, is this:

/storage/extSdCard/

I found mine using a terminal and did:

cd /storage/extSdCard/

then once in the root of the card, I used the "ls" command to list files, so I could verify what was stored on it. Thats how I found mine. Hope it helps someone else.

like image 28
user271918 Avatar answered Sep 27 '22 16:09

user271918