dotintent / FlutterBleLib

Bluetooth Low Energy library for Flutter with support for simulating peripherals
Apache License 2.0
536 stars 197 forks source link

enableRadio() doesn't emit error when radio's already enabled #462

Open xandros6 opened 4 years ago

xandros6 commented 4 years ago

Hi, version 2.2.4, on Android 6.0.1 API level 23 (Sony Xperia Z3 Compact) With Bluetooth already eanbled. on code:

if (Platform.isAndroid) {
    log.v('enableRadio');
    await _bleManager.enableRadio();
}

the call to _bleManager.enableRadio() never finish. If Bluetooth is previously disabled it works.

As a workaround, I can every time disable and enable the radio, but I think there is a better way.

Thanks.

mikolak commented 4 years ago

I'll see about fixing it, but you can call BleManager.bluetoothState() to check if it's enabled or BleManager.observeBluetoothState() to monitor the state.

mikolak commented 4 years ago

From what I see the adapter is returning an error if you're trying to enable an enabled radio. https://github.com/Polidea/MultiPlatformBleAdapter/blob/master/android/library/src/main/java/com/polidea/multiplatformbleadapter/BleModule.java#L1188

The returned error has error code: BleErrorCode.BluetoothStateChangeFailed (105). Can you surround your call to enable with try/catch and confirm that it really is stuck and not just terminating the rest of the flow because of an uncaught error?

xandros6 commented 4 years ago

BleErrorCode.BluetoothStateChangeFailed is not emitted, so I use BleManager.bluetoothState() as you suggest.

Thanks!

mikolak commented 4 years ago

Oh! It should be emitted! I'll use this issue to track it, if you don't mind? I'll have to fix it sometime.