Android-监听SD卡状态(BroadcastReceiver)

注册广播接收者:
 
     
         
         
         
         
     



SDStatusReceiver中获取广播

public class SDStatusReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		//判断收到的到底是什么广播
		String action = intent.getAction();
		if("android.intent.action.MEDIA_MOUNTED".equals(action)){
			Toast.makeText(context, "SD卡可用", 0).show();
		}
		else if("android.intent.action.MEDIA_REMOVED".equals(action)){
			Toast.makeText(context, "SD卡拔出", 0).show();
		}
		else if("android.intent.action.MEDIA_UNMOUNTED".equals(action)){
			Toast.makeText(context, "SD卡不可用", 0).show();
		}
	}
}

























你可能感兴趣的:(Android-基础,Android,监听SD卡状态)