android get external sd card path

public static HashSet getExternalMounts() {

final HashSet out = new HashSet();

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;

}

你可能感兴趣的:(android get external sd card path)