handleUsbDeviceAttached

Adds a USB device to the ExternalNfcReaderStore if it doesn't exist already.

This can be used from an Activity like this:

class MainActivity : FragmentActivity() {

// [...]

private fun handleIntent(intent: Intent) {
if (intent.action == UsbManager.ACTION_USB_DEVICE_ATTACHED) {
val device = IntentCompat.getParcelableExtra(
intent,
UsbManager.EXTRA_DEVICE,
UsbDevice::class.java
)
if (device != null) {
lifecycle.coroutineScope.launch {
val app = App.getInstance()
app.initialize()
app.externalNfcReaderStore.handleUsbDeviceAttached(device)
}
}
}
}
}

Return

a ExternalNfcReaderUsb representing device, either newly added or previously added.

Parameters

device

a UsbDevice received from handling the UsbManager.ACTION_USB_DEVICE_ATTACHED intent.