專案中要做**掃瞄,需要檢測sd插拔事件。寫了個demo分析下。
mreceiver = new broadcastreceiver()
};
//onreceive方法:
private void onreceivemediabroadcast(intent intent) else if (action.equals(intent.action_media_unmounted)) else if (action.equals(intent.action_media_scanner_started)) else if (action.equals(intent.action_media_scanner_finished)) else if (action.equals(intent.action_media_bad_removal))
else if (action.equals(intent.action_media_eject))
else if (action.equals(intent.action_media_removed))
}
//註冊廣播接收器:
intentfilter intentfilter = new intentfilter();
intentfilter.addaction(intent.action_media_mounted);
intentfilter.addaction(intent.action_media_unmounted);
intentfilter.addaction(intent.action_media_scanner_started);
intentfilter.addaction(intent.action_media_scanner_finished);
intentfilter.addaction(intent.action_media_eject);
intentfilter.addaction(intent.action_media_bad_removal);
intentfilter.addaction(intent.action_media_removed);
intentfilter.adddatascheme("file");
registerreceiver(mreceiver, intentfilter);
log資訊:
插卡:系統打出來的狀態,->->->
我的程式列印資訊,android.intent.action.media_unmounted->android.intent.action.media_mounted
->android.intent.action.media_scanner_started->android.intent.action.media_scanner_finidhed
拔卡:系統打出來的狀態,->->
我的程式列印資訊,android.intent.action.media_eject->android.intent.action.media_unmounted
->android.intent.action.media_removed
sd卡插拔廣播
sd卡插入和拔出的廣播 media bad removal action 廣播 擴充套件介質 擴充套件卡 已經從 sd 卡插槽拔出,但是掛載點 mount point 還沒解除 unmount android.intent.action.media bad removal string media ...
SDcard 插拔廣播
media bad removal action 廣播 擴充套件介質 擴充套件卡 已經從 sd 卡插槽拔出,但是掛載點 mount point 還沒解除 unmount android.intent.action.media bad removal string media eject action...
Android 應用層監聽外接SD卡插拔
直接拔出外接sd卡,很可能收不到intent.action media unmounted廣播,具體原因未跟 但是可以使用 storageeventlistener 物件來處理,具體做法 1.獲取storage service服務 mstoragemanager storagemanager thi...