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

Man*_*l M 5 java android core-bluetooth bluetooth-lowenergy google-glass

我有一个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
}
Run Code Online (Sandbox Code Playgroud)

writeOk永远false.我调试了它,发现原因是属性.无论在iOS端设置什么属性,bgc.getProperties()总是返回50.50PROPERTY_READ,PROPERTY_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;
...
}
Run Code Online (Sandbox Code Playgroud)

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

我试过了:

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

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

Man*_*l M 2

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