如何解决Gatt 描述符写入仅返回一次成功
在 Android 低功耗蓝牙中,Gatt Descriptor 写入仅返回一次成功。
我有一个外围设备,有 4 个服务,分别具有 1、3、2、4 个特征,其中一些是可通知的,一些是可指示的。
我已经编写了下面的代码来通过写入描述符来启用通知,但它在写入描述符(行 ABC)时只返回一次成功,在其余情况下它返回 false。
更多关于我的 gatt 写入特性总是返回 false。代码有什么问题
for(BluetoothGattService service : services) {
for(BluetoothGattCharacteristic characteristic : service.getcharacteristics()) {
for (BluetoothGattDescriptor bluetoothGattDescriptor : characteristic.getDescriptors()) {
if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_INDICATE) == 0) {
bluetoothGattDescriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);//0x02,0x00
gatt.setCharacteristicNotification(characteristic,true);
}
if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) == 0) {
bluetoothGattDescriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);//0x01,0x00
// gatt.setCharacteristicNotification(characteristic,true);
}
if(gatt.writeDescriptor(bluetoothGattDescriptor)) //line ABC
{
Log.i(TAG,"characteristics Descriptor Written Successfully");
}
else
{
Log.i(TAG,"characteristics Descriptor Writing Failure");
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。