Android 像 0x0001 这样的 ble setValue

Android ble setValue like 0x0001

我需要在 BLE setValue() 中发送 0x0001、0x0002 等值,

有谁知道怎么转发吗?

例如:

private void command () {
   ongoing.setValue(0x0001);  //error
   mBluetoothLeService.writeCharacteristic(ongoing);
   BluetoothLeService.setCharacteristicNotification(ongoing, true);
   ...
   ...
   ...
   mBluetoothLeService.readCharacteristic(ongoing);
}

Thanks.

在 DeviceControlActivity.java 中:

private void displayGattServices(List<BluetoothGattService> gattServices){
    UUID UBI_COMMAND = UUID.fromString(SampleGattAttributes.UBI_ONGOING_INFO_SERVICE_UUID);
    ...
    ...
    if (uuid.equals(SampleGattAttributes.UBI_ONGOING_INFO_SERVICE_UUID)){
       ongoing = gattService.getCharacteristic(UBI_ONGOING);
    }
}

首先定义你的输入格式(字节)然后设置字符的值。请检查以下代码段。 "writeCharacterstics" 功能在 BluetoothGatt 中可用。如果您的服务中没有您定义的方法,那么还要将 "mBluetoothLeService" 对象更改为 "gatt" 对象以写入值。

            byte[] value = {(byte) 0x01};
            characteristic.setValue(value);
            mBluetoothLeService.writeCharacteristic(characteristic);