admin管理员组文章数量:1312946
I'm developing a feature on Tablet to detect whenever user connect to a QR scanner device - for example: BC-NL3000UⅡ. So far, I'm using broadcast receiver to detect whenever USB_STATE
changes which worked when I test it with other devices like keyboards, or connected through usb port on PC but it did not work on QR Scan devices. It didn't detect or notify (like plugged in or plugged out) whenever i connected to a QR Scan device. My methods weren't called for that.
This is my code to detect:
if (intent.action == "android.hardware.usb.action.USB_STATE") {
val isConnected = intent.getBooleanExtra("connected", false) || device != null
if (isConnected) {
sendEventToFlutter("onUsbConnected")
} else {
sendEventToFlutter("onUsbDisconnected")
}
}
when (intent.action) {
UsbManager.ACTION_USB_DEVICE_ATTACHED -> {
if (device != null) {
sendEventToFlutter("onUsbConnected")
}
}
UsbManager.ACTION_USB_DEVICE_DETACHED -> {
sendEventToFlutter("onUsbDisconnected")
}
}
How can I proper detect when a QR scan device is connected or disconnected?
本文标签: flutterdetect when android device is connected to a qr scanner deviceStack Overflow
版权声明:本文标题:flutter - detect when android device is connected to a qr scanner device - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741869843a2402128.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论