Android广播接收者SD卡监听

1、新建一个类,继承BroadcastReceiver

public class SdcardStateReceiver extends BroadcastReceiver {

	//当sd状态发生改变的时候执行
	@Override
	public void onReceive(Context context, Intent intent) {

		//获取到当前广播的事件类型
		String action = intent.getAction();
		
		if ("android.intent.action.MEDIA_MOUNTED".equals(action)) {
			System.out.println("说明sd卡挂载了 ....");
		}else if ("android.intent.action.MEDIA_UNMOUNTED".equals(action)) {
			System.out.println("说明sd卡卸载了 ");
		}		
	}

}

2、在配置文件添加receiver


            
                
                
                
                
                 
            
 

你可能感兴趣的:(Android开发)