//usb插入監聽 新增廣播過濾意圖
intentfilter filter = new intentfilter();
filter.addaction("android.hardware.usb.action.usb_device_attached");
filter.addaction("android.hardware.usb.action.usb_device_detached");
filter.addaction("android.hardware.usb.action.usb_state");
registerreceiver(musbbroadcastreceiver, filter);
//boolean為成員變數,自己隨便起乙個就行
broadcastreceiver musbbroadcastreceiver = new broadcastreceiver()
if (action.equals("android.hardware.usb.action.usb_device_detached"))
}//判斷儲存usb
if (action.equals("android.hardware.usb.action.usb_state")) else }}
//判斷耳機
if (action.equals("android.intent.action.headset_plug"))
} if (intextra == 1)
if (inttype == 1)
} }
boolean = true;}};
最後廣播在ondestory裡面unregister一下就行
private
void
setbroadcast(long restflow)
ctrl+r進入命令列介面後按照如下格式傳送廣播
"adb shell am broadcast -a 你的廣播 "
Android監聽USB插拔事件
android監聽usb插拔事件有兩種方式 一種是在mainifest.xml中註冊 android.hardware.usb.action.usb device attached即在usb插入是的action意圖。在android.hardware.usb.usbmanager類中有多種actio...
QT 監聽USB熱插拔事件
過濾windows的事件訊息,其中wm devicechange是裝置發生變化時的windows發給各個程式的事件訊息,再通過wparam判斷是裝置插入 dbt devicearrival 還是拔出 dbt deviceremovecomplete 在qt中新增兩個檔案。usb listener.c...
新增sdcard插拔事件的監聽廣播
接收廣播的mreceiver private final broadcastreceiver mreceiver new broadcastreceiver 廣播的註冊 intentfilter intentfilter new intentfilter intentfilter.addaction...