I'm developing an app for the specific device. When i get external storage path it gives me the location, that is placed on internal memory. I need to find out if there is any removable sd card found on device(true,false).
Asked
Active
Viewed 889 times
4
-
1possible duplicate of [How can I get external SD card path for Android 4.0+?](http://stackoverflow.com/questions/11281010/how-can-i-get-external-sd-card-path-for-android-4-0) – Robert Feb 27 '15 at 16:28
-
You are out of luck. Android does not provide a method for that. You should let the user of your app indicate it. – greenapps Feb 27 '15 at 18:13
2 Answers
0
Use this code to check external sdcard present or not
Boolean isSDPresent = android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
if(isSDPresent){
}else{
}

Fahim
- 12,198
- 5
- 39
- 57
-
-
-
This returns the state of the **primary** external storage. The poster's statement translates to the fact that the primary external storage path on the device they are testing points to an onboard memory, rather than a removable card. – Chris Stratton Feb 27 '15 at 19:08
-
no, its not what i'm looking for. i need to find info about removable sd card. Sometimes external storage can be the internal memory of device. – Jenya Kirmiza Mar 02 '15 at 09:52
0
It worked for me
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;
}

Jenya Kirmiza
- 511
- 8
- 21