我有充當BLE中央,並連接到一個BLE外圍(這是使用核心藍牙iOS設備)一個Android(玻璃)應用程序。我正在嘗試從和中讀取寫入外設。的Android BLE:不能寫一個特性(無PROPERTY_WRITE)
閱讀工作正常(並且接收通知也可以正常工作)。
但是我沒有設法寫出一個特徵。這裏是我的代碼:
@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
。 50
是PROPERTY_READ
,PROPERTY_NOTIFY
和PROPERTY_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 4.4.2(Glass XE18.11)。
可以請你建議我如何閱讀特性從iOS到Android? – Rajesh