You can register BroadcastReceiver to listen for changes in the external storage state:
BroadcastReceiver externalStorageStateReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { updateExternalStorageState(); } }; IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_MEDIA_MOUNTED); filter.addAction(Intent.ACTION_MEDIA_REMOVED); registerReceiver(mExternalStorageReceiver, filter); updateExternalStorageState();
And in updateExternalStorageState() you can check the actual state after the change:
protected void updateExternalStorageState() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { // SD card is mounted and ready for use } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { // SD card is mounted, but it is read only } else { // SD card is unavailable } }
source share