Tuesday, January 8, 2013

Check if sdcard is present


How  to check if media is mounted:
boolean mExternalStorageAvailable = false;
boolean mExternalStorageWriteable = false;
String state = Environment.getExternalStorageState();


if (Environment.MEDIA_MOUNTED.equals(state)) {
                       // We can read and write the media
                       mExternalStorageAvailable = mExternalStorageWriteable = true;
                       Log.d("readnwrite", "readandwrite");
                   }
else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
                       // We can only read the media
                       mExternalStorageAvailable = true;
                       mExternalStorageWriteable = false;
                       Log.d("readonly", "readonly");
                   }
 else {
                       // Something else is wrong. It may be one of many other states, but all we need   to know is we can neither read nor write
                              Log.d("notworking", "notworking");
                       mExternalStorageAvailable = mExternalStorageWriteable = false;
                   }


No comments:

Post a Comment