1

此Beacon 设备的 BluetoothGattDescriptor 为 NULL

在此处输入图像描述

这是我的代码:

BluetoothGattCharacteristic characteristic = mBluetoothGatt.getService(UUID.fromString("00001800-0000-1000-8000-00805f9b34fb"))
                            .getCharacteristic(UUID.fromString("00002a00-0000-1000-8000-00805f9b34fb"));

        mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);
        BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString("00002902-0000-1000-8000-00805f9b34fb")); // HERE descriptor = NULL
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        mBluetoothGatt.writeDescriptor(desc);


        characteristic.setValue("newName".getBytes());
        mBluetoothGatt.writeCharacteristic(characteristic);

为什么描述符是NULL?

4

2 回答 2

0

根据您的代码,除非特征没有通知属性,否则它不应为 null。您确定远程设备针对此特定特性将特性客户端配置描述符添加到其 GATT 表中吗?只需仔细检查它,请执行以下操作:在发现服务的位置设置断点并在调试器中查找特征。找到特征属性,看看特征属性是否有这个值:PROPERTY_NOTIFY

常数值:16 (0x00000010)

或者,记录属性值:characteristic.getProperties ()

于 2015-12-14T08:13:05.833 回答
0

似乎,这是因为某些设备(我的是三星 E5)支持 BLE 但不支持 BluetoothGattDescriptor 0x2902(见链接)

要查看设备中支持的所有描述符,请调用:

for (BluetoothGattDescriptor descriptor:characteristic.getDescriptors()){
                    Log.e(TAG, "BluetoothGattDescriptor: "+descriptor.getUuid().toString());
                }
于 2015-12-09T13:45:18.230 回答