amoLink / bluetooth_print_plus

A flutter plugin for bluetooth thermal printer support Android & iOS
MIT License
12 stars 4 forks source link

Sample app not working, can not scan bluetooth devices #14

Closed phongbm closed 3 months ago

phongbm commented 3 months ago

I run the sample project and press the Search button, but an error occurred, the application could not find the list of devices.

Performing hot restart...
Syncing files to device SM A715F...
Restarted application in 2,181ms.
I/flutter (31679): ******************* cur device status: 12
I/ViewRootImpl@2c780d5[MainActivity](31679): ViewPostIme pointer 0
I/ViewRootImpl@2c780d5[MainActivity](31679): ViewPostIme pointer 1
D/BluetoothPrintPlusPlugin(31679): start scan 
I/BluetoothAdapter(31679): startDiscovery
E/MethodChannel#bluetooth_print_plus/methods(31679): Failed to handle method call
E/MethodChannel#bluetooth_print_plus/methods(31679): java.lang.IllegalStateException: Reply already submitted
E/MethodChannel#bluetooth_print_plus/methods(31679):    at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:431)
E/MethodChannel#bluetooth_print_plus/methods(31679):    at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:272)
E/MethodChannel#bluetooth_print_plus/methods(31679):    at com.example.bluetooth_print_plus.bluetooth_print_plus.BluetoothPrintPlusPlugin.onMethodCall(BluetoothPrintPlusPlugin.java:184)
E/MethodChannel#bluetooth_print_plus/methods(31679):    at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
E/MethodChannel#bluetooth_print_plus/methods(31679):    at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)
E/MethodChannel#bluetooth_print_plus/methods(31679):    at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/MethodChannel#bluetooth_print_plus/methods(31679):    at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/MethodChannel#bluetooth_print_plus/methods(31679):    at android.os.Handler.handleCallback(Handler.java:942)
E/MethodChannel#bluetooth_print_plus/methods(31679):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#bluetooth_print_plus/methods(31679):    at android.os.Looper.loopOnce(Looper.java:226)
E/MethodChannel#bluetooth_print_plus/methods(31679):    at android.os.Looper.loop(Looper.java:313)
E/MethodChannel#bluetooth_print_plus/methods(31679):    at android.app.ActivityThread.main(ActivityThread.java:8762)
E/MethodChannel#bluetooth_print_plus/methods(31679):    at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#bluetooth_print_plus/methods(31679):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
E/MethodChannel#bluetooth_print_plus/methods(31679):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
E/DartMessenger(31679): Uncaught exception in binary message listener
E/DartMessenger(31679): java.lang.IllegalStateException: Reply already submitted
E/DartMessenger(31679):     at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:431)
E/DartMessenger(31679):     at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:287)
E/DartMessenger(31679):     at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)
E/DartMessenger(31679):     at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/DartMessenger(31679):     at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/DartMessenger(31679):     at android.os.Handler.handleCallback(Handler.java:942)
E/DartMessenger(31679):     at android.os.Handler.dispatchMessage(Handler.java:99)
E/DartMessenger(31679):     at android.os.Looper.loopOnce(Looper.java:226)
E/DartMessenger(31679):     at android.os.Looper.loop(Looper.java:313)
E/DartMessenger(31679):     at android.app.ActivityThread.main(ActivityThread.java:8762)
E/DartMessenger(31679):     at java.lang.reflect.Method.invoke(Native Method)
E/DartMessenger(31679):     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
E/DartMessenger(31679):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
I/flutter (31679): Error starting scan.
E/flutter (31679): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(startScan, Need android.permission.BLUETOOTH_SCAN permission for AttributionSource { uid = 11468, packageName = com.example.bluetooth_print_plus.bluetooth_print_plus_example, attributionTag = null, token = android.os.BinderProxy@77830b8, next = null }: Starting discovery., java.lang.SecurityException: Need android.permission.BLUETOOTH_SCAN permission for AttributionSource { uid = 11468, packageName = com.example.bluetooth_print_plus.bluetooth_print_plus_example, attributionTag = null, token = android.os.BinderProxy@77830b8, next = null }: Starting discovery.
E/flutter (31679):  at com.android.bluetooth.Utils.checkPermissionForDataDelivery(Utils.java:917)
E/flutter (31679):  at com.android.bluetooth.Utils.checkScanPermissionForDataDelivery(Utils.java:976)
E/flutter (31679):  at com.android.bluetooth.btservice.AdapterService$AdapterServiceBinder.startDiscovery(AdapterService.java:2788)
E/flutter (31679):  at com.android.bluetooth.btservice.AdapterService$AdapterServiceBinder.startDiscovery(AdapterService.java:2776)
E/flutter (31679):  at android.bluetooth.IBluetooth$Stub.onTransact(IBluetooth.java:1002)
E/flutter (31679):  at android.os.Binder.execTransactInternal(Binder.java:1321)
E/flutter (31679):  at android.os.Binder.execTransact(Binder.java:1280)
E/flutter (31679): , null)
E/flutter (31679): #0      BluetoothPrintPlus.scan (package:bluetooth_print_plus/bluetooth_print_plus.dart:85:7)
E/flutter (31679): <asynchronous suspension>
E/flutter (31679): #1      _nullDataHandler (dart:async/stream_impl.dart:517:1)
E/flutter (31679): <asynchronous suspension>
E/flutter (31679): 
amoLink commented 3 months ago

I'm not sure why Try using a different phone

phongbm commented 3 months ago

I see the log:

Unhandled Exception: PlatformException(startScan, Need android.permission.BLUETOOTH_SCAN permission for AttributionSource { uid = 11468, packageName = com.example.bluetooth_print_plus.bluetooth_print_plus_example, attributionTag = null, token = android.os.BinderProxy@27502e, next = null }: Starting discovery., java.lang.SecurityException: Need android.permission.BLUETOOTH_SCAN permission for AttributionSource { uid = 11468, packageName = com.example.bluetooth_print_plus.bluetooth_print_plus_example, attributionTag = null, token = android.os.BinderProxy@27502e, next = null }: Starting discovery.

And I added permissions in AndroidManifest.xml file, but it is still not working, same crash log. image I think the application has bug. My phone: Samsung A71 - Android 13 - API 33

amoLink commented 3 months ago

try: bluetooth_print_plus: ^2.1.1 I have introduced easyterminations to handle permission issues, you can try it out

amoLink commented 3 months ago

The latest version is:bluetooth_print_plus: ^2.1.5 I made some adjustments

navyzhou926 commented 3 months ago

The latest version is:bluetooth_print_plus: ^2.1.5 I made some adjustments

startScan(MethodCall call, Result result),此方法里已经执行了result.success(null),那么在调用startScan的时候后面一行不用再执行result.success(null),不然导致重复回调结果报错

图片

amoLink commented 3 months ago

👍