As for most APIs, there is no word about thread safety in the Bluetooth 
GATT API documentation.

I have implemented a driver for the HM-10 BLE module, which is an UART 
adapter. It has one GATT characteristic for reading and writing data. So I 
get notifications about incoming data in the onCharacteristicChanged() 
callback function of my BluetoothGattCallback implementation. These 
callbacks are called from a "Binder" thread which the Android framework 
maintains. To write data, I need to call setValue() on the 
BluetoothGattCharacteristic object and call writeCharacteristic() on the 
BluetoothGatt instance afterwards. This is done from a thread of my app.

And here is the problem: Unsurprisingly, BluetoothGattCharacteristic is not 
thread safe: What sometimes happens is that the Value property of my 
BluetoothGattCharacteristic gets overwritten during my write operation, 
when incoming data is received in the very same moment.

Any idea how to solve this? Is it somehow possible to place the code for 
writing data in the same thread where the BluetoothGattCallback callbacks 
occur?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to