Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android可设置值,如0x0001_Android_Bluetooth Lowenergy_Setvalue - Fatal编程技术网

Android可设置值,如0x0001

Android可设置值,如0x0001,android,bluetooth-lowenergy,setvalue,Android,Bluetooth Lowenergy,Setvalue,我需要在BLE setValue()中发送类似0x0001、0x0002的值 有人知道如何传播吗 例如: private void command () { ongoing.setValue(0x0001); //error mBluetoothLeService.writeCharacteristic(ongoing); BluetoothLeService.setCharacteristicNotification(ongoing, true); ... ..

我需要在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);
    }
}
private void displaytsetservices(列出gattServices){
UUID UBI_COMMAND=UUID.fromString(samplegattatattributes.UBI_continuous\u INFO\u SERVICE\u UUID);
...
...
if(uuid.equals(samplegattatattributes.UBI\u持续的\u信息\u服务\u uuid)){
持续=gattService.getCharacteristic(UBI_持续);
}
}

首先定义输入格式(字节),然后设置字符的值。请检查下面的代码片段。“WriteCharacteristics”功能在蓝牙GATT中可用。如果您在自己定义的服务中没有方法,那么也可以将“mBluetoothLeService”对象更改为“gatt”对象以写入值

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

首先定义输入格式(字节),然后设置字符的值。请检查下面的代码片段。“WriteCharacteristics”功能在蓝牙GATT中可用。如果您在自己定义的服务中没有方法,那么也可以将“mBluetoothLeService”对象更改为“gatt”对象以写入值

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

正在进行的的类型是什么?它应该是BluetoothGattCharacteristic,因为它被传递给一个需要它的方法?我只读过,但在这里可以看到以下内容:。。。值得注意的是,您可以使用像@Override public void onCharacteristicWrite这样的实际方法(BluetoothGatt gatt,…写入数据。但您可能没有按照链接正确写入。正在进行的
类型是什么?
?它应该是BluetoothGattCharacteristic的,因为它被传递给需要它的方法?我只读过,但在这里看到了用于写入的内容:…值得注意的是,您可以使用实际的方法,如@Override ppublic void onCharacteristicWrite(BluetoothGatt gatt,…)来写入数据。但您可能没有按照链接正确写入数据。