Reputation: 11
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?
Upvotes: 1
Views: 55