I´m working with a BLE112
device and my Callback-method onCharacteristicChanged(...)
isn´t triggered on my Android App.
In my gatt.xml file, i defined this service:
<service uuid="4300" advertise="true" id="entry_service">
<description>Entry_Service</description>
<characteristic uuid="4301" id="unlock_state">
<description>Unlock_State</description>
<properties read="true" write="true" notify="true"/>
<value length="1">0</value>
<descriptor uuid="4381">
<properties read="true" write="true"/>
<value length="1">0</value>
</descriptor>
</characteristic>
</service>ode here
And i´m trying to enable notifications with this Code:
BluetoothGattService service = ble112Device.getBluetoothGatt().getService(uuidService);
BluetoothGattCharacteristic characteristic = service.getCharacteristic(uuidChar);
if( !ble112Device.getBluetoothGatt().setCharacteristicNotification(characteristic, true)) // returns true
Log.d("NOTIFICATION", "Setup failed.");
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(uuidDescr);
if(!descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE)) // returns true
Log.d("DESCRIPTOR", "error");
else if(!mBluetoothLeService.writeDescriptor(ble112Device, descriptor)) // returns true
Log.d("DESCRIPTOR", "write error");
In my Logchat, i get acknowledgements for writing the descriptor etc., but onCharacteristicChanged(...)
is never called. Can anyone help?
在您的GATT.XML文件中更改属性的顺序。
<properties notify="true" read="true" write="true" />
I solved this issue. You have to use the UUID:0x2902, when getting the descriptor.
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(uuidDescr); //uuidDescr must be 0x2902
You don´t have to write your own descriptors in your gatt.xml. Just get and write the descriptor with UUID 0x2902 of your characteristic you want to be notified.
After that, onCharacteristicChanged()
fired properly.
The descriptor with UUID 2902 is called Client Characteristic Configuration 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.