繁体   English   中英

Android BLE:无法写一个特征(没有PROPERTY_WRITE)

[英]Android BLE: cannot write a Characteristic (no PROPERTY_WRITE)

我有一个Android(Glass)应用程序,它充当BLE中心并连接到BLE外围设备 (使用Core Bluetooth的iOS设备)。 我正在尝试读取写入外设。

阅读工作正常(接收通知也很好)。

但是我没有设法写出一个特征。 这是我的代码:

@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
  if (status == BluetoothGatt.GATT_SUCCESS) {
    BluetoothGattService bse = gatt.getService(TRANSFER_SERVICE_UUID);
    BluetoothGattCharacteristic bgc = bse.getCharacteristic(TRANSFER_CHARACTERISTIC_UUID);
    bgc.setValue("Hello");
    boolean writeOk = gatt.writeCharacteristic(bgc);
  }
}

@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
  // never called
}

writeOk总是false 我调试了它,发现原因是属性。 无论在iOS端设置了什么属性, bgc.getProperties()始终返回50 50PROPERTY_READPROPERTY_NOTIFYPROPERTY_INDICATE ,但缺少PROPERTY_WRITE ,因此BluetoothGatt.writeCharacteristic()立即退出:

public boolean writeCharacteristic(BluetoothGattCharacteristic characteristic) {
    if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE) == 0
        && (characteristic.getProperties() &
            BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) == 0) return false;
...
}

在我看来,属性不能从iOS外设正确传输到Android中心。 使用iOS中央连接到iOS外围设备时,属性会正确传输并且可以正常写入。

我试过了:

所以 - 我在Android方面做错了吗? 如果不是:这是一个错误吗? 或者iOS是否只想从iOS设备获取写入?

我使用的是Android 4.4.2(Glass XE18.11)。

似乎这是Android BLE API中的一个错误。 在最新更新(Glass XE18.3)之后,此行为消失,并且传输属性按预期工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM