Reputation: 3226
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?
Upvotes: 6
Views: 18545
Reputation: 11
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.
Upvotes: 1
Reputation: 2154
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.
Upvotes: 2
Reputation: 39
I think /storage/sdcard0/ is used for internal sdcard and /storage/sdcard1/ is used for external sd card if there are two storage option present. if you are checking a file is present either in any of sdcard or not you should check all possible paths.
String path;
if(new File("/storage/sdcard/yourpath").exist())
{
path="/storage/sdcard/yourpath";
}
else if(new File("/storage/sdcard0/yourpath").exists())
{
path="/storage/sdcard0/yourpath";
}
else if(new File("/storage/sdcard1/yourpath").exists())
{
path="/storage/sdcard1/yourpath";
}
Upvotes: 0
Reputation: 446
You should use
Environment.getExternalStorageDirectory().getAbsolutePath()
Upvotes: 1
Reputation: 52936
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.
Upvotes: 5