查看文档
setCharacteristicNotification
仅显示一个构造函数
boolean setCharacteristicNotification (BluetoothGattCharacteristic characteristic,
boolean enable)
因此,您需要首先创建
BluetoothGattCharacteristic
从您的UUID,例如:
public static final UUID SERIAL_SERVICE = UUID.fromString("0000ffe0-0000-1000-8000-00805f9b34fb");
public static final UUID SERIAL_VALUE = UUID.fromString("0000ffe1-0000-1000-8000-00805f9b34fb");
BluetoothGattCharacteristic characteristic = gatt.getService(SERIAL_SERVICE).getCharacteristic(SERIAL_VALUE);
然后设置通知
gatt.setCharacteristicNotification(characteristic,true);
最后,设置客户端特征配置描述符以允许服务器启动的更新
public static final UUID CONFIG_DESCRIPTOR = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
BluetoothGattDescriptor desc = characteristic.getDescriptor(CONFIG_DESCRIPTOR);
desc.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
gatt.writeDescriptor(desc);
最后一部分使您能够从设备接收通知。CCCD的UUID始终相同。