I have an Android (Glass) application that acts as a BLE central and connects to a BLE peripheral (which is an iOS device using Core Bluetooth). I am trying to read from and write to the peripheral.
Reading works fine (and receiving notifications works fine too).
However I didn't manage to write a characteristic. Here's my code:
@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
is always false
. I debugged it and found out that the reason is the properties. bgc.getProperties()
always returns 50
, no matter what properties are set on the iOS side. 50
is PROPERTY_READ
, PROPERTY_NOTIFY
and PROPERTY_INDICATE
, but its missing PROPERTY_WRITE
, so BluetoothGatt.writeCharacteristic()
immediately exits:
public boolean writeCharacteristic(BluetoothGattCharacteristic characteristic) {
if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE) == 0
&& (characteristic.getProperties() &
BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) == 0) return false;
...
}
It seems to me that the properties are not transmitted correctly from the iOS peripheral to the Android central. When connecting to the iOS peripheral with an iOS central, the properties are transmitted correctly and writing works.
I have tried:
So - am I doing anything wrong on the Android side? If not: Is this a bug? Or does iOS only wants to get writes from iOS devices?
I am using Android 4.4.2 (Glass XE18.11).
Seems that this was a bug in the Android BLE API. After the latest update (Glass XE18.3) this behaviour is gone and transmitting the Properties works as expected.
You can maybe find the answer at this link:
https://devzone.nordicsemi.com/question/1423/writing-to-a-characteristic-using-the-android-43-api/
Regards
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With