dotintent / FlutterBleLib

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

Device side disconnection is not detected on android #615

Open patolax opened 2 years ago

patolax commented 2 years ago

I want to detect the device shutdown when the app is already connected. At the moment I dont see an approch to do this on android.


I listen to observeConnectionState, but this stream is not emiting anything on device disconnect. 
 _bleDeviceConnectionStateSubscription = peripheral
        .observeConnectionState(
            emitCurrentValue: false, completeOnDisconnect: true)
        .listen((connectionState) {
      print(
          "Peripheral ${device.peripheral.identifier} connection state is $connectionState");
      _bleDeviceConnectionStateSubject.add(connectionState);
    });

I also tired calling isConnected method, however even when device is shutdown it returns true.

var connection = await _bleDevice.peripheral.isConnected();

Is there a way to monitor device side disconnection and show a message to the user.