Skip to content

Conversation

@nphuoc1625
Copy link

usbDevice.deviceName could be null and resulted in app crash immediately

usbDevice.deviceName could be null
resulted in app crash immediately
@nphuoc1625
Copy link
Author

nphuoc1625 commented Jun 16, 2025

E/AndroidRuntime(10736): FATAL EXCEPTION: main
E/AndroidRuntime(10736): java.lang.RuntimeException: Error receiving broadcast Intent { act=com.flutter_pos_printer.USB_PERMISSION flg=0x10 } in com.sersoluciones.flutter_pos_printer_platform.usb.USBPrinterService$mUsbDeviceReceiver$1@7dee852
E/AndroidRuntime(10736): at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$android-app-LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1800)
E/AndroidRuntime(10736): at android.app.LoadedApk$ReceiverDispatcher$Args$$ExternalSyntheticLambda0.run(Unknown Source:2)
E/AndroidRuntime(10736): at android.os.Handler.handleCallback(Handler.java:942)
E/AndroidRuntime(10736): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(10736): at android.os.Looper.loopOnce(Looper.java:201)
E/AndroidRuntime(10736): at android.os.Looper.loop(Looper.java:288)
E/AndroidRuntime(10736): at android.app.ActivityThread.main(ActivityThread.java:7918)

@nphuoc1625
Copy link
Author

[Update USBPrinterService.kt, use use an explicit intent with a packageName]

Fix bug that intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED always return false even when accepted permission when connect USB device

From https://developer.android.com/about/versions/14/behavior-changes-14#safer-intents

I used an Explicit Intent that passed in context.packageName, also changed PendingIntent.FLAG_IMMUTABLE to PendingIntent.FLAG_MUTABLE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant