use*_*929 2 java uuid android bluetooth-lowenergy sensors
我需要CLIENT_CHARACTERISTIC_CONFIGUUID 来激活我的应用程序中的通知。在谷歌示例应用程序中,它们是预定义的:
public static String HEART_RATE_MEASUREMENT = "00002a37-0000-1000-8000-00805f9b34fb";
public static String CLIENT_CHARACTERISTIC_CONFIG = "00002902-0000-1000-8000-00805f9b34fb";
Run Code Online (Sandbox Code Playgroud)
我所拥有的只是:
- 双向服务:b9e875c0-1cfa-11e6-b797-0002a5d5c51b
- 接收:0c68d100-266f-11e6-b388-0002a5d5c51b
- 发送:1ed9e2c0-266f-11e6-850b-0002a5d5c51b
如何获取 UUID:
mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(needed UUID here));
descriptor.setValue(enabled?BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : new byte[]{0x00, 0x00});
mBluetoothGatt.writeDescriptor(descriptor);
Run Code Online (Sandbox Code Playgroud)
客户端特征配置的 UUID 为 0x2902,或者长格式为“00002902-0000-1000-8000-00805f9b34fb”,如应用程序中已定义的那样。
附带说明一下,您可以找到所有支持的描述符及其 UUID,如 Nick Unucheck 的回答所示: