Previously, USBPrinterAdapter().getInstance() worked same as constructor instantiating.
Changed getInstance to static method and disposed the static instance on onDetachedFromEngine
2. mUsbDeviceReceiver receiver always receives null for usbDevice
Checked in Android 12 & 13, the intent extra for UsbManager.EXTRA_DEVICE is always null.
So, add the vendorId and productId to pendingIntent while requesting permissions.
If UsbManager.EXTRA_DEVICE is null, then try to init usb device with vendorId and productId.
3. Moved pendingIntent from class scope to local scope
Since pending intent is only required when requesting permission, moved variable to local scope
Changes
1. Changed
USBPrinterAdapter
to singleton class.Previously,
USBPrinterAdapter().getInstance()
worked same as constructor instantiating. ChangedgetInstance
to static method and disposed the static instance ononDetachedFromEngine
2.
mUsbDeviceReceiver
receiver always receives null forusbDevice
Checked in Android 12 & 13, the intent extra for
UsbManager.EXTRA_DEVICE
is always null.So, add the
vendorId
andproductId
to pendingIntent while requesting permissions. IfUsbManager.EXTRA_DEVICE
is null, then try to init usb device withvendorId
andproductId
.3. Moved
pendingIntent
from class scope to local scopeSince pending intent is only required when requesting permission, moved variable to local scope