<receiver android:name="com.shiwenjie.sd.sd">
<intent-filter >
<action android:name="android.intent.action.MEDIA_UNMOUNTED"/>
<action android:name="android.intent.action.MEDIA_MOUNTED"/>
<action android:name="android.intent.action."/>
<!--想让上面的这2个事件生效 必须的加上这样的一个data -->
<data android:scheme="file"/>
</intent-filter>
</receiver>
public class sd extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
//[1]获取到当前广播的事件类型
String action = intent.getAction();
//[2]对action做一个判断
if("android.intent.action.MEDIA_UNMOUNTED".equals(action)){
System.out.println("说明sd卡 卸载了");
}else if ("android.intent.action.MEDIA_MOUNTED".equals(action)) {
System.out.println("说明sd卡挂载了");
}
}
}