Android ble setValue如0x0001

时间:2017-06-06 06:40:21

标签: android bluetooth-lowenergy setvalue

我需要在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);
    }
}

1 个答案:

答案 0 :(得分:1)

首先定义输入格式(字节),然后设置charactertics的值。请查看下面的代码段。 &#34; writeCharacterstics&#34;功能在BluetoothGatt中可用。如果您在自己定义的服务中没有方法,那么也要更改&#34; mBluetoothLeService&#34;反对&#34; gatt&#34;对象写入值。

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