Wednesday, October 6, 2010

How do I – Android: Check if SD card is present

Sometimes its necessary to know whether device has SD card present (mounted), before start doing any operation(s) with it. So, here is some simple way to determine is SD card mounted:

/**
 * Checks if SD card is mounted.
 *
 * @return True, if SD card is mounted.
 */
public boolean isSDCardMounted() {
      return android.os.Environment.getExternalStorageState().equals(
            
android.os.Environment.MEDIA_MOUNTED);
}

That’s it, if its mounted, you’ll get true, otherwise false.

No comments :

Post a Comment