我正在尝试使用 BluetoothGattCharacteristic 方法 setValue(..) 在香水分配器设备中写入十六进制值 0xFF 。我在回调方法 onCharacteristicWrite() 中获得成功状态代码 0 但设备不执行任何操作,理想情况下它应该发出香味.
下面是我写入特性的示例代码
private void writeCharacteristic(CallbackContext callbackContext, UUID serviceUUID, UUID characteristicUUID, byte[] data, int writeType) {
boolean success = false;
if (gatt == null) {
callbackContext.error("BluetoothGatt is null");
return;
}
BluetoothGattService service = gatt.getService(serviceUUID);
BluetoothGattCharacteristic characteristic = findWritableCharacteristic(service, characteristicUUID, writeType);
if (characteristic == null) {
callbackContext.error("Characteristic " + characteristicUUID + " not found.");
} else {
int data2=0xFF;
characteristic.setValue(data2, BluetoothGattCharacteristic.FORMAT_UINT16, 0);
characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
writeCallback = callbackContext;
if (gatt.writeCharacteristic(characteristic)) {
success = true; …Run Code Online (Sandbox Code Playgroud) android ×1