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?
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/ .
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.
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.
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.
You should use
Environment.getExternalStorageDirectory().getAbsolutePath()
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With