characteristic.getDescriptor()返回null

我正在连接计步器到android。 当我在setCharacteristicNotification函数中执行以下行时,我将描述符设为Null

BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG)); public static String CLIENT_CHARACTERISTIC_CONFIG = "00002902-0000-1000-8000-00805f9b34fb"; 

为什么它返回一个空值?

characteristic.getUuid()返回正确的值。

似乎你的设备不支持这个0x2902 BluetoothGattDescriptor尝试查看你的所有描述符:

  for (BluetoothGattDescriptor descriptor:characteristic.getDescriptors()){ Log.e(TAG, "BluetoothGattDescriptor: "+descriptor.getUuid().toString()); } 

尝试这个:

 public final BluetoothGattCallback btleGattCallback = new BluetoothGattCallback() { @Override public void onConnectionStateChange( BluetoothGatt gatt,int status,int newState) { if (status == BluetoothGatt.GATT_SUCCESS && newState == BluetoothProfile.STATE_CONNECTED) { discoverServices(); } } @Override public void onServicesDiscovered(BluetoothGatt gatt,int status) { BluetoothGattService service =gatt.getService(UUIDS.SERVICE_UUID); BluetoothGattCharacteristic characteristic; characteristic = service.getCharacteristic(UUIDS.CHARACTERSTICS_UUID); BluetoothGattDescriptor descriptor=characteristic.getDescriptor(UUIDS.CONFIG_DESCRIPTOR); } }