Why does setCharacteristicNotification() not actually enable notifications?
NickName:Timmmm Ask DateTime:2014-04-03T00:01:30

Why does setCharacteristicNotification() not actually enable notifications?

The BluetoothLeGatt Android BLE example contains the following code:

public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic,
                                          boolean enabled) {
    if (mBluetoothAdapter == null || mBluetoothGatt == null) {
        Log.w(TAG, "BluetoothAdapter not initialized");
        return;
    }
    mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);

    // This is specific to Heart Rate Measurement.
    if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) {
        BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
                UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        mBluetoothGatt.writeDescriptor(descriptor);
    }
}

My question is basically, why is the marked code specific to Heart Rate Measurement? It seems like having a Client Characteristic Config Descriptor (CCCD) characteristic is the standard way to control characteristic notification, so why doesn't setCharacteristicNotification() take care of writing to it? And since it doesn't do that, what does setCharacteristicNotification() actually do?

I'm pretty new to BLE and there aren't any explanations of it on the internet that don't assume that you already understand it all! So don't assume I know what a CCCD or whatever is! It was difficult enough finding out what CCCD even stands for!

Edit: See also this answer which supports my understanding of CCCDs (and makes me continue to wonder why you have to write to them manually in Android when there is a function that looks like it should do that for you): https://devzone.nordicsemi.com/index.php/what-does-cccd-mean

Copyright Notice:Content Author:「Timmmm」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/22817005/why-does-setcharacteristicnotification-not-actually-enable-notifications

Answers
Davide Giovanelli 2014-10-09T15:38:06

I think is a litte bit late for give an answer but today I had the same doubt and I found a clear answer.\nUsing setCharacteristicNotification() you enable notification localy (on android device) and setting CCC descriptor to ENABLE_NOTIFICATION_VALUE you enable notification on ble peripheral. In fact for enabling CCC notification you have to use setValue() and writeDescriptor() that are methods used for writing characteristics (in this case characteristics descriptors) to remote device.\nI found this on: http://processors.wiki.ti.com/index.php/SensorTag_User_Guide",


More about “Why does setCharacteristicNotification() not actually enable notifications?” related questions

Why does setCharacteristicNotification() not actually enable notifications?

The BluetoothLeGatt Android BLE example contains the following code: public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic,

Show Detail

What does BluetoothGatt.setCharacteristicNotification() do?

Reading the documentation, one would think that setCharacteristicNotification enables notifications for a BLE characteristic: Enable or disable notifications/indications for a given characteri...

Show Detail

Android BluetoothGatt not receving Characteristic Notifications BluetoothGatt#writeDescriptor(desc) return false

I am working on an application which needs to communicate with a Bluetooth LE device. This is the code I use to set the CharacteristicNotification public boolean setCharacteristicNotification(

Show Detail

Android BLE , setCharacteristicNotification() doesn't work

I have 6 characteristics on my device. One of them needs notification to send data. I register characteristics like this : private void registerEnvironmentCharacteristics(List<

Show Detail

How to enable notifications on exactly 2 characteristics in Android?

I want to be able to receive notifications on exactly 2 characteristics. Said characteristics are RX and TX from the perspective of the BLE device I am communicating with. I have succeeded in doing...

Show Detail

Android BLE set multiple notifications for multiple ble devices

Ok so I was wondering how this can be achieved. I have tried putting all of the characteristics that i want to read and get notifications from into 2 separate queues. One for readCharacteristics an...

Show Detail

Android: How Do BLE Notifications Work?

On Android when you want to receive BLE notifications for characteristic changes you use something like the following: BluetoothGattCharacteristic characteristic = ... gatt.setCharacteristicNotifi...

Show Detail

setCharacteristicNotification doesn't trigger onCharacteristicChanged

I try to read peripheral's characteristic however onCharacteristicChanged is never called despite setting up setCharacteristicNotification. Method which gets my characteristic: private void

Show Detail

Bluetooth LE listen to multiple characteristic notifications

I'm using BLE application on an Android phone communicating with a custom BLE sensor board. There are two characteristics provided by the board, acceleration and ecg. On the phone side, I'd like to

Show Detail

Programmatically turning on all notifications

I am new to Android development and I can't understand how to properly turn all ble notifications and get all of them. I've tried to loop through all services for(BluetoothGattService service : ...

Show Detail