Java Android BLE:无法写入特征(无属性\u写入)
我有一个Android(Glass)应用程序,它充当BLE中心并连接到BLE外围设备(这是一个使用核心蓝牙的iOS设备)。我正在尝试从读取和向外围设备写入 阅读效果很好(接收通知也很好) 然而,我没有写出一个特征。这是我的密码:Java Android BLE:无法写入特征(无属性\u写入),java,android,bluetooth-lowenergy,google-glass,core-bluetooth,Java,Android,Bluetooth Lowenergy,Google Glass,Core Bluetooth,我有一个Android(Glass)应用程序,它充当BLE中心并连接到BLE外围设备(这是一个使用核心蓝牙的iOS设备)。我正在尝试从读取和向外围设备写入 阅读效果很好(接收通知也很好) 然而,我没有写出一个特征。这是我的密码: @Override public void onServicesDiscovered(BluetoothGatt gatt, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { Bluetoot
@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
。我调试了它,发现原因是属性bgc.getProperties()
始终返回50
,无论在iOS端设置了什么属性<代码>50是属性读取
,属性通知
和属性指示
,但它缺少属性写入
,因此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 central。使用iOS central连接到iOS外围设备时,可以正确传输属性并进行写入
我试过:
- 配对设备
- 使用()
我使用的是Android 4.4.2(Glass XE18.11)。您可以在以下链接中找到答案:
这似乎是Android BLE API中的一个bug。在最新的更新(Glass XE18.3)之后,这种行为消失了,传输属性的工作与预期一样。据我所知,这个问题的问题是外围设备没有授予写入权限。在我的情况下,外围设备授予我写权限,但它们不会显示在中央的Android API中。你能建议我如何从ios到Android读取特征吗?我使用的是索尼、摩托罗拉5版和4.4.4版的设备。但未写入错误为写入失败。