android - Gatt 描述符写作只返回一次成功
问题描述
在 Android Bluetooth Low energy 中,Gatt Descriptor 写入仅返回一次成功。
我有一个具有 4 个服务的外围设备,分别具有 1、3、2、4 个特性,其中一些是可通知的,有些是可指示的。
我编写了下面的代码以通过编写描述符来启用通知,但它只在编写描述符(ABC 行)一次时返回成功,而对于其余情况,它返回 false。
更多关于我的 gatt 写入特性总是返回错误。代码有什么问题
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");
}
解决方案
推荐阅读
- python - 在python的单行循环内添加多个条件
- r - 连接字符串中的自定义因子级别
- bootstrap-4 - Flexbox 不能正常工作(当我点击 M 屏幕尺寸时不要转动)
- python - str.translate 方法没有替代
- nsis - 如何使用 NSIS 在 Windows 安装程序完成页面中设置默认选中的复选框
- python - 在 h5py 中什么是类型“|V15060”
- python - 如何使用 Chalice 和 Boto3 显示项目 dynamodb
- c++ - 如何在 Eigen 中禁用并行化
- java - 贪吃蛇游戏:画身体
- react-native - v3 中 React 导航底部选项卡栏的图标不显示