Detecting if the Sd-Card had been mounted in Android
Here is short article on how to detect if the sd-card had been mounted on android.
Quick Explanation
String storagestate = Environment.getExternalStorageState();
--- This line gets the storage state, external means your sd-card, change it to internal then it means get the state of your phone memory.
if (!storagestate.equals(Environment.MEDIA_MOUNTED) ) { }
--- This check if the storage's state is mounted, then ! at the front would reverse the result. For more values to compare to, see Environment class
Update History
Jan 17, 2012 - Visual Update
String storagestate = Environment.getExternalStorageState();
if (!storagestate.equals(Environment.MEDIA_MOUNTED) ) {
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle(this.getText(R.string.error_sd_card_title));
alertDialog.setMessage(this.getText(R.string.error_sd_card_desc));
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
return;
} });
alertDialog.show();
}
Quick Explanation
String storagestate = Environment.getExternalStorageState();
--- This line gets the storage state, external means your sd-card, change it to internal then it means get the state of your phone memory.
if (!storagestate.equals(Environment.MEDIA_MOUNTED) ) { }
--- This check if the storage's state is mounted, then ! at the front would reverse the result. For more values to compare to, see Environment class
Update History
Jan 17, 2012 - Visual Update
No comments: