检查USB是否连接
程序员文章站
2024-02-11 14:56:40
...
//
/**
* 检测USB是否连接
*/
private BroadcastReceiver mUSBReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
LogUtil.i("插入USB,继续线程", "log.txt");
UpdatePresenter.IOSource oldIOSrc = mUpdatePresenter.getIOSource();
LogUtil.i("连接USB" + mUpdatePresenter.getIOSource() + ",mIOSource:" + oldIOSrc);
mUpdatePresenter.setIOSource(UpdatePresenter.IOSource.RS232);
ToastUtil.showLong(App.application, "连接USB");
}
if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
boolean isSuccess = mUpdatePresenter.restoreBackupIOSource();
if (!isSuccess) {
mUpdatePresenter.setIOSource(UpdatePresenter.IOSource.BLUETOOTH);
}
LogUtil.i("断开USB,暂停线程", "log.txt");
ToastUtil.showLong(App.application, "断开USB");
}
}
};
上一篇: Linux 获取物理网口/或虚拟网络接口