1,USB存储设备(如:U盘,移动硬盘):
//USB存储设备 插拔监听与 SD卡插拔监听一致。
private USBBroadCastReceiver mBroadcastReceiver;
IntentFilter iFilter = new IntentFilter();
iFilter.addAction(Intent.ACTION_MEDIA_EJECT);
iFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
iFilter.addAction(Intent.ACTION_MEDIA_REMOVED);
iFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);iFilter.addDataScheme(“file”);
mBroadcastReceiver = new USBBroadCastReceiver();
registerReceiver(mBroadcastReceiver, iFilter);
private class USBBroadCastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(Intent.ACTION_MEDIA_EJECT)) {
//USB设备移除,更新UI
} else if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) {
//USB设备挂载,更新UI
}
}
<