Skip to content Skip to sidebar Skip to footer

Android Ble Oncharacteristicchanged() Using Notify Not Triggered

I made an app that communicates with an device via BLE. I wrote everything that was required for it's communication. The device receives the sent value via characteristic.setValue(

Solution 1:

i have notification work flawlessly with BLE.

i created this method to mark a characteristics notification enabled.

publicvoidmarkCharForNotification(BluetoothGattCharacteristic readableChar) {

        mBluetoothGatt.setCharacteristicNotification(readableChar, true);

        List<BluetoothGattDescriptor> listDescr = readableChar.getDescriptors();

        BluetoothGattDescriptor descriptor = listDescr.get(0);
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        mBluetoothGatt.writeDescriptor(descriptor);

    }

hope it helps

Solution 2:

You might want to run the checkCharacteristicProperties on the notify characteristic also.

Anyway, the correct way to enable notifications is to check the properties first and enable notify or indicate, based on those properties:

BluetoothGattDescriptordescriptor= characteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID);
    intproperties= characteristic.getProperties();
    if (descriptor != null) {
        if ((properties & BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) {
            descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        } elseif ((properties & BluetoothGattCharacteristic.PROPERTY_INDICATE) > 0) {
            descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
        }
        gatt.writeDescriptor(descriptor);

Hope this helps.

Post a Comment for "Android Ble Oncharacteristicchanged() Using Notify Not Triggered"