I want to check whether the SD card is available on the device or not. Now Android devices provide internal device memory and the Android system considers that memory at path Environment.getExternalStorageDirectory()
. So when we check the SD card state system, it always says it's available. How can I differentiate between these two types of memory?

- 10,145
- 15
- 56
- 70

- 1,295
- 2
- 18
- 30
-
But there is no correct answer for it. – User10001 Mar 31 '14 at 18:23
4 Answers
You can get the state:
String state = Environment.getExternalStorageState();
Then, for example, if you want to check if the SDCARD is mounted :
if (Environment.MEDIA_MOUNTED.equals(state))
You can find further information in http://developer.android.com/reference/android/os/Environment.html.
There is a nice SO post here talking about detecting mounted sd card via USB.. Regards.
Update:
External storage is not the same as SD card, at least not on all devices. Devices that have internal flash memory (for example my Nexus 4 does) threat this as " external storage".
Now, devices that have both internal flash and SD card, threat internal flash as external memory and SD card is then added as directory under this external memory.
From programmers view it's a pain, but not much we can do about it. There is a nice so post here taking more about External Storage
.
-
1Android devices now provides inbuilt internal storage and that one present at String state = Environment.getExternalStorageState(); so if SDcard present or not it always return true. any help below all codes are not working. – User10001 Jan 28 '14 at 12:53
-
There's a method for that: Environment.isExternalStorageEmulated(). Also check Environment.isExternalStorageRemovable().

- 3,809
- 2
- 33
- 39
There is a code that check if memory card is available or not.
File file=new File("/sys/block/mmcblk1");
String sd_cid = null;
try {
String memBlk;
if (file.exists() && file.isDirectory()) {
memBlk = "mmcblk1";
} else {
//System.out.println("not a directory");
memBlk = "mmcblk0";
}
Process cmd = Runtime.getRuntime().exec("cat /sys/block/"+memBlk+"/device/cid");
BufferedReader br = new BufferedReader(new InputStreamReader(cmd.getInputStream()));
sd_cid = br.readLine();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if sd_cid is null then memory card is not avail.

- 1,821
- 1
- 20
- 31
Environment.isExternalStorageRemovable()
provide info whether your externalstorage is removable or not.if it is return true it means your external storage is removale so it means SD card is present on the device.

- 1,295
- 2
- 18
- 30