我需要在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);
}
}
答案 0 :(得分:1)
首先定义输入格式(字节),然后设置charactertics的值。请查看下面的代码段。 &#34; writeCharacterstics&#34;功能在BluetoothGatt中可用。如果您在自己定义的服务中没有方法,那么也要更改&#34; mBluetoothLeService&#34;反对&#34; gatt&#34;对象写入值。
byte[] value = {(byte) 0x01};
characteristic.setValue(value);
mBluetoothLeService.writeCharacteristic(characteristic);