1

In my phone I have two storages, one of them is SD card and the other is extsdcard.

I can get the sdcard path by:

Environment.getExternalStorageDirectory()
.toString()

How do I get the extsdcard file path?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
RealDream
  • 407
  • 3
  • 6
  • 18

1 Answers1

2

Use this to get the other external sdcard:

 File storageDir=   new File("/mnt/external_sd/")

OR

 File storageDir=   new File("/mnt/extSdCard/")

For more details see http://mono-for-android.1047100.n5.nabble.com/detect-SD-Card-path-td5710218.html#a5710250 and this

So that Like this use a function to get list of all ext cards...

public static HashSet<String> getExternalMounts() {
    final HashSet<String> out = new HashSet<String>();
    String reg = "(?i).*vold.*(vfat|ntfs|exfat|fat32|ext3|ext4).*rw.*";
    String s = "";
    try {
        final Process process = new ProcessBuilder().command("mount")
                .redirectErrorStream(true).start();
        process.waitFor();
        final InputStream is = process.getInputStream();
        final byte[] buffer = new byte[1024];
        while (is.read(buffer) != -1) {
            s = s + new String(buffer);
        }
        is.close();
    } catch (final Exception e) {
        e.printStackTrace();
    }

    // parse output
    final String[] lines = s.split("\n");
    for (String line : lines) {
        if (!line.toLowerCase(Locale.US).contains("asec")) {
            if (line.matches(reg)) {
                String[] parts = line.split(" ");
                for (String part : parts) {
                    if (part.startsWith("/"))
                        if (!part.toLowerCase(Locale.US).contains("vold"))
                            out.add(part);
                }
            }
        }
    }
    return out;
}
Community
  • 1
  • 1
Arun C
  • 9,035
  • 2
  • 28
  • 42
  • how can i get the string (path) by programmaticlly? – RealDream May 21 '13 at 08:43
  • String path=storageDir.getAbsolutePath(); – Arun C May 21 '13 at 08:44
  • 2
    Hardcoding sdcard path is not a good idea, it may be different on different devices – pedja May 21 '13 at 08:49
  • Maybe yot are not clear with the quastion, the quastion is that: if you have two storage sdcard and extended sdcard yo can get the files in the sd card by Environment.getExternalStorageDirectory() .toString() this way, for the other one is there any similar way to get the files? – RealDream May 21 '13 at 08:49
  • Use a function like getExternalMounts() – Arun C May 21 '13 at 08:56