If we call setCharacteristicNotification on a character, not giving Remote Notification on value Change? How to enable the remote Notification on a Central Device in Bluetooth LE ?
TO enable Remote Notification on Android,
setCharacteristicNotification(characteristic, enable) is not enough.
Need to write the descriptor for the characteristic. Peripheral has to enable characteristic notification while creating the characteristic.
Once the Notify is enabled , it will have a descriptor with handle 0x2902 . so we need to write BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE to the descriptor. First Convert 0x2902 to 128 bit UUID, it will be like this 00002902-0000-1000-8000-00805f9b34fb (Base Bluetooth UUID is 0000xxxx-0000-1000-8000-00805f9b34fb).
Code below
protected static final UUID CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
* Enable Notification for characteristic
*
* @param bluetoothGatt
* @param characteristic
* @param enable
* @return
*/
public boolean setCharacteristicNotification(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic characteristic,boolean enable) {
Logger.d("setCharacteristicNotification");
bluetoothGatt.setCharacteristicNotification(characteristic, enable);
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID);
descriptor.setValue(enable ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : new byte[]{0x00, 0x00});
return bluetoothGatt.writeDescriptor(descriptor); //descriptor write operation successfully started?
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With