0

I stop getting onCharacteristicChanged after exiting the app and restarting it.

Here are the steps I did pairing to a ble device.

  1. I have a service that contains the ble logic and persist the bluetoothGatth obj, I perform a blueToothGatt.connect here on app launch.
  2. Once I get onConnectionStateChange with STATE_CONNECTED, I call blueToothGatt.discover
  3. On the onServicesDiscovered callback, I will fetch and persist the services and characteristics that I care about. Then I will call blueToothGatt.setCharacteristicNotification and write to descriptor to enable notification.
  4. Now I perform a write and then I will get callback for onCharacteristicChange just fine.
  5. 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 on unbind callback and call selfstop to stop the service. Now if I relaunch the app. I will do the same steps 1-4, however this time around onCharacteristicChange 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!

galath
  • 5,717
  • 10
  • 29
  • 41
Yoong
  • 54
  • 3

1 Answers1

0

I found the solution to this. Basically the bluettooth caching the last handle, so discover services is never triggered. You will need to clear the device cache after connect.

How to programmatically force bluetooth low energy service discovery on Android without using cache

Community
  • 1
  • 1
Yoong
  • 54
  • 3