【问题标题】:Android ble setValue like 0x0001Android ble setValue like 0x0001
【发布时间】:2017-06-06 06:40:21
【问题描述】:

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

【问题讨论】:

  • ongoing的类型是什么?
  • 它应该是 BluetoothGattCharacteristic,因为它被传递给需要它的方法?
  • 我只读过,但看到这里写作:stackoverflow.com/questions/36163998/… ...值得注意的是,你可以使用像@Override public void onCharacteristicWrite(BluetoothGatt gatt, ....写入数据。但您可能没有按照链接正确写入。

标签: android bluetooth-lowenergy setvalue


【解决方案1】:

首先定义您的输入格式(字节),然后设置字符的值。请检查下面的sn-p。 BluetoothGatt 中提供了“writeCharacterstics”功能。如果您的服务中没有您定义的方法,那么还将“mBluetoothLeService”对象更改为“gatt”对象以写入值。

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

【讨论】:

    猜你喜欢
    • 2017-11-13
    • 2018-02-11
    • 2010-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-08
    • 1970-01-01
    相关资源
    最近更新 更多