Closed sobels closed 1 year ago
This was caused by me using an outdated library version (specifically, the one located in this repository). You might want to update that version to eliminate confusion, but anyway updating to the latest SDK fixed my problem.
You can reproduce this by plugging in a scanner for which the app doesn't already have permission. On my device it instantly crashes 100% of the time.
According to the stack trace and decompiled code, the problem is in the
USBManager.getAvailableScannersList()
method. If it does not already have permission to open the attached device, it constructs an intent to get permission for that device withPendingIntent.getBroadcast(context, 0, new Intent(ACTION_USB_PERMISSION), 0)
.While this has been a warning for a while now, starting in Android 12 this will crash every time - callers now have to specify either
PendingIntent.FLAG_MUTABLE
orPendingIntent.FLAG_IMMUTABLE
when calling this method. In your case, you should probably replace this withPendingIntent.getBroadcast(context, 0, new Intent(ACTION_USB_PERMISSION), PendingIntent.FLAG_MUTABLE)
.tl;dr Use
PendingIntent.getBroadcast(context, 0, new Intent(ACTION_USB_PERMISSION), PendingIntent.FLAG_MUTABLE)