3

Using the api logic you can detect if the sd card is available for read or write, but it doesn't tell you why it is not writable.

I want to know if the user even has a sd card vs if it just mounted.

Is this possible?

cottonBallPaws
  • 21,220
  • 37
  • 123
  • 171
  • possible duplicate of [How to tell if the sdcard is mounted in Android?](http://stackoverflow.com/questions/902089/how-to-tell-if-the-sdcard-is-mounted-in-android) - Specifically, the accepted answer shows a method that does it. – wkl Feb 02 '11 at 19:28
  • I did see that one, but MEDIA_MOUNTED refers to the card being mounted to the device. The language is a little confusing. I am looking for a way to tell the difference between mounted to the device (available to read/write), mounted to something external like a computer (not available) and the phone not having a card at all (also not available). Since I posted this question I noticed there are some other constants available here http://developer.android.com/reference/android/os/Environment.html one of them being MEDIA_REMOVED. I believe that one will do what I am looking for. – cottonBallPaws Feb 02 '11 at 20:10

2 Answers2

7

for example:

String state = Environment.getExternalStorageState();

if (state.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {

}

Check out the possible constants at : http://developer.android.com/reference/android/os/Environment.html#getExternalStorageState%28%29

Stéphane
  • 6,920
  • 2
  • 43
  • 53
6
public static boolean isSdPresent() {

return android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);

}
Harinder
  • 11,776
  • 16
  • 70
  • 126