6

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?

Samuel
  • 9,883
  • 5
  • 45
  • 57
Farhan
  • 3,206
  • 14
  • 49
  • 62
  • 1
    Environment.getExternalStorageDirectory is _defined_ to return the "external storage" directory, however that is no longer necessarily a removable card. It never returns the "internal storage" directory (classically the /data partition). There may not be an Android-wide standard for how to determine the path of a removable sdcard on a system which also has a soldered in "external storage" partition, as that seems to be more a vendor extension than an upstream android feature. – Chris Stratton Aug 31 '11 at 02:57
  • 1
    Yes, I agree with you. I too think that there is no way of determining the path of a removable sdcard. This should have been implemented because sometimes an application may give an option to the user to either choose internal storage or external storage. In that case, either you hard-code directory paths for individual devices (Which is not a good idea considering different devices available today) or Android should come up with a public API.. – Farhan Aug 31 '11 at 08:26
  • @Farhan Have you managed to find any solutions yet ? I am looking for the same. did you try /proc/mount with with any reasonable success ? – Ahmed Jan 27 '13 at 23:02

6 Answers6

5

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.

Nikolay Elenkov
  • 52,576
  • 10
  • 84
  • 84
  • I've noticed it's usually `/mnt/sdcard`, but is that universal? – Nathan Moos Aug 31 '11 at 03:35
  • `/mnt/sdcard` is usually the path to external storage, but I don't think it's universal. Additional SD cards (such as on the Xoom or Iconia) are mounted some place else. I've seen references to 'secondary external storage', but no API for it in the SDK. – Nikolay Elenkov Aug 31 '11 at 03:57
  • Yes, in devices like Xoom, Galaxy Tab, Asus Tablets, Samsung Galaxy S2 and many more. /mnt/sdcard usually points to internal storage; not external sd-card storage. – Farhan Aug 31 '11 at 08:22
  • Thanks Nikolay for your answer.. I too have found that there is currently no public API for accessing the mount location of a removable sd-card in devices where getExternalStorageDirectory() returns the path of internal shared storage. Looks like I have to try making my own library :) – Farhan Aug 31 '11 at 08:23
  • Try the /proc/mount idea, and look for entries that look like they could be external storage volumes - fairly large and under a path of the form /mnt* or (for legacy) /sd* – Chris Stratton Aug 31 '11 at 12:16
2

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.

Dustin
  • 2,064
  • 1
  • 16
  • 12
1

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.

user271918
  • 11
  • 1
1

You should use

Environment.getExternalStorageDirectory().getAbsolutePath()
basicsharp
  • 446
  • 3
  • 8
  • 1
    Please check my question again.I wrote that Environment.getExternalStorageDirectory() not necessarily returns the absolute path of the real external (sd card) directory. – Farhan Aug 31 '11 at 08:21
0

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";
     }
Abhishek
  • 39
  • 6
-1

String path=ExternalStorageDirectoryPath + "/foldername/";

Saad Asad
  • 2,528
  • 3
  • 20
  • 27