rohitsangwan01 / ble_peripheral

A Flutter plugin that allows you to use your device as Bluetooth Low Energy (BLE) peripheral
MIT License
12 stars 13 forks source link

java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: Binder:10909_3 #2

Closed alisherbu closed 8 months ago

alisherbu commented 1 year ago

java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: Binder:10909_3 at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:1449) at io.flutter.embedding.engine.FlutterJNI.dispatchPlatformMessage(FlutterJNI.java:1070) at io.flutter.embedding.engine.dart.DartMessenger.send(DartMessenger.java:282) at io.flutter.embedding.engine.dart.DartExecutor$DefaultBinaryMessenger.send(DartExecutor.java:470) at io.flutter.embedding.engine.dart.DartExecutor.send(DartExecutor.java:223) at io.flutter.plugin.common.BasicMessageChannel.send(BasicMessageChannel.java:106) at com.rohit.ble_peripheral.BleCallback.onWriteRequest(BlePeripheral.g.kt:490) at com.rohit.ble_peripheral.BlePeripheralPlugin$gattServerCallback$1.onCharacteristicWriteRequest(BlePeripheralPlugin.kt:373) at android.bluetooth.BluetoothGattServer$1.onCharacteristicWriteRequest(BluetoothGattServer.java:219) at android.bluetooth.IBluetoothGattServerCallback$Stub.onTransact(IBluetoothGattServerCallback.java:256) at android.os.Binder.execTransactInternal(Binder.java:1220) at android.os.Binder.execTransact(Binder.java:1179)

Steps:

  1. Start advertising from first device
  2. Pair and connect as a second device
  3. call Characteristic.write([0x12, 0x34]) from second device And crashes in first advertisible device

Please help me!

rohitsangwan01 commented 1 year ago

@alisherbu seems like the characteristic write handler callback is executing on main thread you can try to wrap this with handler.post {} like this If it works fine for you, the please send a PullRequest for this Fix

alisherbu commented 1 year ago

@rohitsangwan01 https://github.com/rohitsangwan01/ble_peripheral/pull/3

rohitsangwan01 commented 8 months ago

Fixed in Version 1.0