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 (将#修改为@)