esc_pos_bluetooth icon indicating copy to clipboard operation
esc_pos_bluetooth copied to clipboard

getBluetoothService() called with no BluetoothManagerCallback

Open danieramiz opened this issue 4 years ago • 1 comments

I'm running the example project "Blue" and I'm getting this error:

/BluetoothBasicPlugin(31020): start scan 
D/BluetoothAdapter(31020): isLeEnabled(): ON
D/BluetoothLeScanner(31020): onScannerRegistered() - status=0 scannerId=9 mScannerId=0
D/BluetoothAdapter(31020): isLeEnabled(): ON
D/BluetoothBasicPlugin(31020): start scan 
D/BluetoothAdapter(31020): isLeEnabled(): ON
D/BluetoothLeScanner(31020): onScannerRegistered() - status=0 scannerId=9 mScannerId=0
D/BluetoothAdapter(31020): isLeEnabled(): ON
D/BluetoothAdapter(31020): isLeEnabled(): ON
D/BluetoothLeScanner(31020): could not find callback wrapper
W/BluetoothAdapter(31020): getBluetoothService() called with no BluetoothManagerCallback
D/BluetoothBasicPlugin(31020): stateStreamHandler, current action: android.bluetooth.device.action.ACL_CONNECTED
E/DeviceConnFactoryManager(31020): wait read 
E/flutter (31020): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: Bad state: Future already completed
E/flutter (31020): #0      _AsyncCompleter.complete (dart:async/future_impl.dart:41:31)
E/flutter (31020): andrey-ushakov/esc_pos_printer#1      PrinterBluetoothManager.writeBytes.<anonymous closure> (package:esc_pos_printer/src/printer_bluetooth_manager.dart:121:19)
E/flutter (31020): andrey-ushakov/esc_pos_printer#2      _rootRunUnary (dart:async/zone.dart:1134:38)
E/flutter (31020): andrey-ushakov/esc_pos_printer#3      _CustomZone.runUnary (dart:async/zone.dart:1031:19)
E/flutter (31020): andrey-ushakov/esc_pos_printer#4      _FutureListener.handleValue (dart:async/future_impl.dart:140:18)
E/flutter (31020): andrey-ushakov/esc_pos_printer#5      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
E/flutter (31020): andrey-ushakov/esc_pos_printer#6      Future._propagateToListeners (dart:async/future_impl.dart:711:32)
E/flutter (31020): andrey-ushakov/esc_pos_printer#7      Future._complete (dart:async/future_impl.dart:516:7)
E/flutter (31020): andrey-ushakov/esc_pos_printer#8      new Future.delayed.<anonymous closure> (dart:async/future.dart:313:16)
E/flutter (31020): andrey-ushakov/esc_pos_printer#9      _rootRun (dart:async/zone.dart:1122:38)
E/flutter (31020): andrey-ushakov/esc_pos_printer#10     _CustomZone.run (dart:async/zone.dart:1023:19)
E/flutter (31020): andrey-ushakov/esc_pos_printer#11     _CustomZone.runGuarded (dart:async/zone.dart:925:7)
E/flutter (31020): andrey-ushakov/esc_pos_printer#12     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:965:23)
E/flutter (31020): andrey-ushakov/esc_pos_printer#13     _rootRun (dart:async/zone.dart:1126:13)
E/flutter (31020): andrey-ushakov/esc_pos_printer#14     _CustomZone.run (dart:async/zone.dart:1023:19)
E/flutter (31020): andrey-ushakov/esc_pos_printer#15     _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:949:23)
E/flutter (31020): andrey-ushakov/esc_pos_printer#16     Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:23:15)
E/flutter (31020): andrey-ushakov/esc_pos_printer#17     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19)
E/flutter (31020): andrey-ushakov/esc_pos_printer#18     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5)
E/flutter (31020): andrey-ushakov/esc_pos_printer#19     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
E/flutter (31020): 
D/BluetoothSocket(31020): close() this: android.bluetooth.BluetoothSocket@a214a42, channel: 1, mSocketIS: android.net.LocalSocketImpl$SocketInputStream@5d8ea53, mSocketOS: android.net.LocalSocketImpl$SocketOutputStream@3f33f90mSocket: android.net.LocalSocket@5502089 impl:android.net.LocalSocketImpl@ffdc88e fd:java.io.FileDescriptor@dfdd8af, mSocketState: CONNECTED
D/BluetoothSocket(31020): close() this: android.bluetooth.BluetoothSocket@a214a42, channel: 1, mSocketIS: android.net.LocalSocketImpl$SocketInputStream@5d8ea53, mSocketOS: android.net.LocalSocketImpl$SocketOutputStream@3f33f90mSocket: null, mSocketState: CLOSED
W/System.err(31020): java.io.IOException: bt socket closed, read return: -1
D/BluetoothSocket(31020): close() this: android.bluetooth.BluetoothSocket@a214a42, channel: 1, mSocketIS: android.net.LocalSocketImpl$SocketInputStream@5d8ea53, mSocketOS: android.net.LocalSocketImpl$SocketOutputStream@3f33f90mSocket: null, mSocketState: CLOSED
W/System.err(31020):    at android.bluetooth.BluetoothSocket.read(BluetoothSocket.java:564)
W/System.err(31020):    at android.bluetooth.BluetoothInputStream.read(BluetoothInputStream.java:88)
W/System.err(31020):    at java.io.InputStream.read(InputStream.java:101)
W/System.err(31020):    at com.gprinter.io.BluetoothPort.readData(BluetoothPort.java:130)
W/System.err(31020):    at com.tablemi.flutter_bluetooth_basic.DeviceConnFactoryManager.readDataImmediately(DeviceConnFactoryManager.java:418)
W/System.err(31020):    at com.tablemi.flutter_bluetooth_basic.DeviceConnFactoryManager$PrinterReader.run(DeviceConnFactoryManager.java:498)
E/BluetoothPort(31020): connection device is lost
E/DeviceConnFactoryManager(31020):  read 0
D/BluetoothBasicPlugin(31020): stateStreamHandler, current action: android.bluetooth.device.action.ACL_DISCONNECTED

I'm using flutter 1.14.6

Flutter doctor: Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel beta, v1.14.6, on Mac OS X 10.15.3 19D76, locale es-419)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2) [✓] Xcode - develop for iOS and macOS (Xcode 11.3.1) [✓] Chrome - develop for the web [✓] Android Studio (version 3.5) [✓] VS Code (version 1.42.1) [✓] Connected device (3 available)

• No issues found!

danieramiz avatar Mar 08 '20 02:03 danieramiz

I found out a StackOverflow case, when they solved it but for Android code. Maybe this could be a guide to implement the same inside the plugin? https://stackoverflow.com/questions/18657427/ioexception-read-failed-socket-might-closed-bluetooth-on-android-4-3/25647197#25647197

danieramiz avatar Mar 11 '20 17:03 danieramiz