Enabling Bluetooth characteristic Notification in Android (Bluetooth Low Energy ) Not Working

后端 未结 3 583
既然无缘
既然无缘 2020-12-19 17:47

If we call setCharacteristicNotification on a character, not giving Remote Notification on value Change? How to enable the remote Notification on a Central

3条回答
  •  一生所求
    2020-12-19 18:16

    To enable notification you should do as following.

    mBluetoothLeService.setCharacteristicNotification(mSampleCharacteristic, true);
    

    of which definition is as following.

    if (enabled) {
                BluetoothGattDescriptor bluetoothGattDescriptor = characteristic.getDescriptor(UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
                bluetoothGattDescriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE); 
                mBluetoothGatt.writeDescriptor(bluetoothGattDescriptor);
            } else {
                BluetoothGattDescriptor bluetoothGattDescriptor = characteristic.getDescriptor(UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
                bluetoothGattDescriptor.setValue(BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE); 
                mBluetoothGatt.writeDescriptor(bluetoothGattDescriptor);
            }
    

    Still if remote notification does not work, try to read characteristics only after enabling notifications for the same.

    Reading characteristics is as

    mBluetoothLeService.readCharacteristic(eachChara);
    

提交回复
热议问题