0

My app needs to save some data on phone's storage. The user can select where the data is saving. I have a problem with an HTC EVO user which didn't see the external card listed in my app.

I'm using Environment.getExternalStorageDirectory().getAbsolutePath() but this leads to the internal SD card, not to the external one. Please tell me what path should I follow(even it's hardcoded) to list the ext sd on his phone? I want to list both SD cards...1 is listed but the other one isn't seen...

Alexandru Circus
  • 5,478
  • 7
  • 52
  • 89

2 Answers2

1

I am not sure about HTC Evo, but unfortunately Android cannot handle the case when there exist two cards such as "/mnt/sdcard (internal) and /mnt/sdcard-ext (external)". getExternalStorageDirectory() will only return /mnt/sdcard.

You can check whether it is internal or external storage by using isExternalStorageRemovable() though. Here is a description for this method:

Returns whether the primary "external" storage device is removable. If true is returned, this device is for example an SD card that the user can remove. If false is returned, the storage is built into the device and can not be physically removed.

Reference: http://developer.android.com/reference/android/os/Environment.html#isExternalStorageRemovable()

Hope this helps.

sam
  • 2,780
  • 1
  • 17
  • 30
0

This should work:

public static File getRemovableStorage() {
    final String value = System.getenv("SECONDARY_STORAGE");
    if (!TextUtils.isEmpty(value)) {
        final String[] paths = value.split(":");
        for (String path : paths) {
            File file = new File(path);
            if (file.isDirectory()) {
                return file;
            }
        }
    }
    return null;
}
Jared Rummler
  • 37,824
  • 19
  • 133
  • 148