This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Android-enable notification client side, CCCD & UUID.

Hi All,

I have a problem to enable notification on my Android phone, i followed the tutorial on android web page (section bluetooth low energy) but my app crash, i have this error :

W/BluetoothGatt: Unhandled exception in callback
                                                                              java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothGattDescriptor.setValue(byte[])' on a null object reference
                                                                                  at com.selfiethings.yacire.selfwakeup2.ConnectionBleService$override.setCharacteristicNotification(ConnectionBleService.java:314)
                                                                                  at com.selfiethings.yacire.selfwakeup2.ConnectionBleService$override.static$access$300(ConnectionBleService.java:31)
                                                                                  at com.selfiethings.yacire.selfwakeup2.ConnectionBleService$override.access$dispatch(ConnectionBleService.java)
                                                                                  at com.selfiethings.yacire.selfwakeup2.ConnectionBleService.access$300(ConnectionBleService.java:0)
                                                                                  at com.selfiethings.yacire.selfwakeup2.ConnectionBleService$2.onServicesDiscovered(ConnectionBleService.java:151)
                                                                                  at android.bluetooth.BluetoothGatt$1.onSearchComplete(BluetoothGatt.java:305)
                                                                                  at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:217)
                                                                                  at android.os.Binder.execTransact(Binder.java:446)

My code to set up the notification on my client (Android app) is like this :

 private void setCharacteristicNotification() {

    BluetoothGattService bluetoothGattService = mBluetoothGatt.getService(UUID.fromString(SELF_WAKE_UP_SERVICE_UUID));
    BluetoothGattCharacteristic bluetoothGattCharacteristic = bluetoothGattService.
            getCharacteristic(UUID.fromString(BATTERY_LEVEL_CHARACTERISTIC_UUID));

    mBluetoothGatt.setCharacteristicNotification(bluetoothGattCharacteristic, true);
    BluetoothGattDescriptor descriptor = bluetoothGattCharacteristic.getDescriptor(
            UUID.fromString(BATTERY_LEVEL_CHARACTERISTIC_UUID));

    Log.i(TAG, "descriptor " + descriptor);
    descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
    mBluetoothGatt.writeDescriptor(descriptor);

}

So, i have an issue at the line : BluetoothGattDescriptor descriptor = bluetoothGattCharacteristic.getDescriptor( UUID.fromString(BATTERY_LEVEL_CHARACTERISTIC_UUID)); My descriptor reference is null. In this link text

I see, to write the CCCD to enable notification, i must have the CCCD_UUID, but what is this CCCD UUID, i have only UUID for charcteristics and services in my server (nrf51 DK). So i need to write this : BluetoothGattDescriptor desc = char.getDescriptor(CCCD_UUID); to enable notif. in Android.

Do you have any information about CCCD UUID please ? Thanks.

Parents Reply Children
No Data
Related