Skip to content

USBPrinterService #6

Open
nphuoc1625 wants to merge 2 commits into
diantahoc:mainfrom
nphuoc1625:main
Open

USBPrinterService #6
nphuoc1625 wants to merge 2 commits into
diantahoc:mainfrom
nphuoc1625:main

Conversation

@nphuoc1625
Copy link
Copy Markdown

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

usbDevice.deviceName could be null
resulted in app crash immediately
@nphuoc1625
Copy link
Copy Markdown
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
Copy Markdown
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

@ubaidsuhail
Copy link
Copy Markdown

One more issue is that on android 14 printer list show but when click on device it does not print.This works for android 13 but in android 14 it give issues.

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.

2 participants