connectivity-samples
connectivity-samples copied to clipboard
setCharacteristicNotification example is wrong
You must writeDescriptor after gatt.setCharacteristicNotification to inform peripheral, it's NOT specific to Heart Rate Measurement.
fun setCharacteristicNotification() {
gatt?.let { gatt ->
gatt.setCharacteristicNotification(characteristic, true)
val CCC_DESCRIPTOR_UUID: UUID = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb")
val descriptor = characteristic?.getDescriptor(CCC_DESCRIPTOR_UUID)?.apply {
value = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
}
gatt.writeDescriptor(descriptor)
https://developer.android.com/guide/topics/connectivity/bluetooth/transfer-ble-data is a bad document. https://developer.android.com/guide/topics/connectivity/bluetooth-le#notification is good document. Please update document and examples, save some time for others