The Samsung Galaxy S3 has an external SD card slot, mounted on the /mnt/extSdCard path.
Environment.getExternalStorageDirectory() How can I find a path through code like this? The above code will return mnt/sdcard. But I can't find the external SD card API (or USB that can be attached and detached for tablet)
Thank you!
android android-sdcard
We've made some changes to the solution we found here.
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;
}
The original method was tested and worked on the following instruments:
I don't remember exactly which Android version it was when I tested it. The modified version of the code was tested on the device below.
And we tested a single storage device that uses an SD card as its main storage device.
Not surprisingly, all the devices returned the path of the removable storage device. Of course, we need to check it out additionally, but I think it's the best solution we've found so far.
© 2024 OneMinuteCode. All rights reserved.