简体   繁体   中英

Android BLE onCharacteristicChanged() not called

I'm working on a project which includes a Bluegiga BLE113 module and an Android app. On the Bluegiga module I've set up several characteristics. For one characteristic I defined a descriptor to activate the clie enter code here nt notification (in My case, the client is the Android app.). The characteristic definition of the BLE113 module looks like this:

 <characteristic uuid="dcfa2671-974d-4e4a-96cd-6221afeabb62"        id="ez1_flow_data_out">
     <!-- org.bluetooth.descriptor.gatt.characteristic_user_description -->
     <description>Data to transmit to Android device</description>
     <properties write="true" read="true" />
     <value variable_length="true" length="255" type="hex" />
     <!-- org.bluetooth.descriptor.gatt.client_characteristic_configuration -->
     <descriptor uuid="2902">
     <properties write="true" read="true" const="false" />
     <!-- Bit 0 = 1: Notifications enabled -->
    <value type="hex">0001</value>
    </descriptor>


   </characteristic>

On the Android side I've set up the notification inside the onServicesDiscovered(...) callback according to the Android Bluetooth Low Energy guide:

characteristic=gatt.getService(BLEuuids.DATAFLOW_SERVICE).getCharacteristic(BLEuuids.DATAFLOW_OUT_CHARACT);
//Enable local notifications
gatt.setCharacteristicNotification(characteristic, true);
//Enabled remote notifications
BluetoothGattDescriptor desc = characteristic.getDescriptor(BLEuuids.DATAFLOW_OUT_DESCRIPT);
boolean test;
test = desc.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); // return value = true
test = gatt.readDescriptor(desc); // return value = true
test = gatt.writeDescriptor(desc); // return value = true

However, if I change the Value of the DATAFLOW_OUT_CHARACT characteristics UUID, using the serial interface of the Bluegiga Module, the intended callback onCharacteristicChanged(...) isn't triggered on My Android app.

Do I have the descriptor set up properly or is it a failure in My Android code?

Now enable the notifications to callback onCharactersticsChanged() and set the properties ENABLE_NOTIFICATION_VALUE and ENABLE_INDICATION_VALUE

Log.d(TAG, "setCharacteristicNotification");
        if (mBluetoothAdapter == null || customBluetoothGatt == null) {
            Log.d(TAG, "BluetoothAdapter not initialized");
            return;
        }cx
        customBluetoothGatt.setCharacteristicNotification(characteristic, enabled);

        BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
        boolean success = customBluetoothGatt.writeDescriptor(descriptor);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM