Hi
I am working on Health & Fitness based android app, which is paired with Smart Ring BLE device. After pairing process app is discovering services for various UUID. For every UUID, app is enabling the Notification, to notify the app whenever any value is triggered from any characteristic. This procedure is working very fine for 95% of android phones.
But I am facing issues with One Plus Nord Android Version 12. Observations are mentioned below :
-
Discover the services -> Enable notification -> Send command to BLE device to receive data from a characteristic -> BLE device disconnecting
-
Discover the services -> Send command to BLE device to receive data from a characteristic -> Enable notification -> Working fine
-
Discover the services -> Send command to BLE device to receive data from a characteristic -> Enable notification -> Worked fine for few minutes but disconnected
-Discover the services -> Send command to BLE device to receive data from a characteristic -> Notification enabled Before -> Worked fine for few minutes but disconnected
-Discover the services -> Send command to BLE device to receive data from a characteristic -> Enable Notification -> No response
I am using same BLE device with other Android model it working very fine no disconnecting issue faced.
I tested this scenario with this github repo and my project facing same behaviour.
What I did to resolve it
- Network and Bluetooth Reset
- Bluetooth Cache clear from system app
- I tried by changing connection interval, slave latency and supervisor timeout in ring side.
Sample code of enabling notification in my project
`
fun queueSetNotificationForCharacteristic(
gatt: BluetoothGatt,
characteristic: BluetoothGattCharacteristic
) {
val ghattQueueItem = GhattQueueItem(
characteristic = characteristic,
enabled = true,
ghatt = gatt,
ghattQueueItemType = SUBSCRIBE_CHARACTERISTIC
)
setNotificationForCharacteristic(ghattQueueItem)
}
private fun setNotificationForCharacteristic(ghattQueueItem: GhattQueueItem) {
ghattQueueItem.ghatt?.let { gatt ->
ghattQueueItem.characteristic?.let { characteristic ->
gatt.setCharacteristicNotification(characteristic, true)
// This is specific to Heart Rate Measurement.
val descriptor = characteristic.getDescriptor(UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU){
gatt.writeDescriptor(descriptor, BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE)
}else{
descriptor.value = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
gatt.writeDescriptor(descriptor)
}
}
}
}
`
Do I need to get descriptor for other UUIDs too and then write descriptor to enable notification value ??
I am stuck here where and how to proceed furthur.