I stop getting onCharacteristicChanged
after exiting the app and restarting it.
Here are the steps I did pairing to a ble device.
- I have a service that contains the ble logic and persist the
bluetoothGatth
obj, I perform ablueToothGatt.connect
here on app launch. - Once I get
onConnectionStateChange
withSTATE_CONNECTED
, I callblueToothGatt.discover
- On the
onServicesDiscovered
callback, I will fetch and persist the services and characteristics that I care about. Then I will callblueToothGatt.setCharacteristicNotification
and write to descriptor to enable notification. - Now I perform a write and then I will get callback for
onCharacteristicChange
just fine. - After this, say I exit the app (device is still paired). The
onDestroy
of the last activity, my ble device service gets unbind...in which I will perform close onunbind
callback and callselfstop
to stop the service. Now if I relaunch the app. I will do the same steps 1-4, however this time aroundonCharacteristicChange
does not get call, also I tried disconnect before close...but that didn't help
(One thing that I do notice is that if the device is left unpaired/disconnected upon relaunch then the issue occurs, however if I power of the BLE device off and turn it back on before restarting the app, then I get the callback onCharacteristicChanged
just fine. This seems like the device is holding onto some setting that prevents onCharacteristics
to get call.)
Any insights to this will be greatly appreciated. Thanks!