Bluetooth Low Energy On Android: Top Tips For The Tricky Bits @ GDG Detroit
Why Stack Overflow recommends it
Stack Overflow users link it when answering Android BLE questions about operations being overwritten, multi-device connections and discovery problems, since it explains the need to queue GATT operations.
Recommended by 4 people across 4 different months, 2018 to 2019.
What it is
A conference talk by Android developer Stuart Kent at GDG Detroit on working with Bluetooth Low Energy on Android. It starts with BLE basics, then walks through code samples and strategies for the quirks of Android's Bluetooth stack, such as undocumented operation queuing and unreliable behavior across devices.
What people said
Recommends Christopher · 2018-01 · Stack Overflow · on “Bluetooth LE Sending String from phone to bluetooth le device”
Just redefine your writeCustomCharacteristic method: public void writeCustomCharacteristic(byte[] payload) { if (mBluetoothAdapter == null || mBluetoothGatt == null) { Log.w(TAG, "BluetoothAdapter not initialized"); return; } /*check if the service is available on the device*/ BluetoothGattService mCustomService = mBluetoothGatt.getService(UUID.fromString("6e400001-b5a3-f393-e0a9-e50e24dcca9e")); if(mCustomService == null){ Log.w(TAG, "Custom BLE Service not found"); return; } /*get the read characteristic from the service*/ BluetoothGattCharacteristic mWriteCharacteristic = mCustomService.getCharacteristic(UUID.fromString("6e400002-b5a3-f393-e0a9-e50e24dcca9e")); mWriteCharacteristic.setVal
Recommends stkent · 2018-10 · Stack Overflow · on “Read and notify BLE android”
As you've observed, you can't start these two operations simultaneously (the first one will be overwritten and never executes): gatt.readCharacteristic(battery); gatt.writeDescriptor(descriptor); Instead, you have to do the first operation, wait for it to finish (in your example, by waiting for onCharacteristicRead to be called), and then start the second operation. A common way to implement this is to use a queue [LINK] to store pending operations, then pop items off the front of the queue and execute them one at a time in the rest of your code. This required queuing is an annoying aspect of the Android BLE APIs that is not described in the documentation. For more details, check out my talk
Recommends Volodymyr Bereziuk · 2018-12 · Stack Overflow · on “Fetching Data Parallel ly from 2 BLE connected Devices”
Its possible to connect up to 7 devices in parallel. I have successfully performed connection with 5 devices. But I do not recommend you to read data in parallel. Android BLE operation should be performed in the queue for all the devices, otherwise your read operation can be just overwritten by next operation. Take look here, to find more information [this video]
Recommends Volodymyr Bereziuk · 2018-12 · Stack Overflow · on “Android BLE discovery issue”
Make sure that GPS is enabled all the time you searching devices. Also suggest you to watch this about BLE [this video]
Recommends jpgpuyo · 2019-07 · Stack Overflow · on “How can I receive data from a BLE Device?”
First of all, read the bluetooth overview [LINK] . Check if bluetooth permissions have been added to the project. One thing that is wrong here is that isConnected=true is set too early, because you can consider that you are connected after ble services has been discovered and (status == BluetoothGatt.GATT_SUCCESS) . Otherwise, you can't read and write characteristics. A good starting point can be this repo [LINK] from google. It is old project and I'm not sure if you have to update some dependency to make it compile, but nothing important. Establish a connection and start reading bytes is easy, but if you want establish a reliable connection with ble device, due to android fragmentation and