polarofficial / polar-ble-sdk

Repository includes SDK and code examples. More info https://polar.com/en/developers
Other
447 stars 147 forks source link

Using connectGatt with autoConnect option on Android to automatically reconnect when device is back in range #450

Open orestesgaolin opened 3 months ago

orestesgaolin commented 3 months ago

Platform your question concerns:

Device:

Description:

We're using Foreground Service to maintain connection with the Verity Sense. However, sometimes when the device is out of range or turned off (which often results with com.polar.androidcommunications.api.ble.exceptions.BleDisconnected exception in polarBleApi.startHrStreaming(deviceId) btw) the service may be terminated due to memory pressure.

We're looking for ways to automatically reconnect the band when it's back in range, and we've noticed that BDDeviceListenerImpl uses connectGatt with false parameter passed (i.e. direct connect). However, we would like to be able to pass true in cases when the device gets disconnected - found this explanation about different modes.

With regards to that I have couple of questions:

  1. Do you know if this would be a good approach to reconnect to the Verity Sense (or any other Polar device supported by the SDK) when it gets back in range or turns on?
  2. Are there any objections to use connectGatt with auto connect option?
  3. If this option doesn't pose any risks, would you be able to expose this parameter in polarBleApi.connectToDevice(deviceId) call?