Android Bluetooth LE - Reading Features Not Working on Samsung

I constantly read the specifications from the BLE device.

I created Runnable in my service class:

private class BackgroundRunnableForRead implements Runnable { private volatile boolean isRunning = true ; @Override public void run() { try { BluetoothLeService.this.backgroundRunID = Thread.currentThread().getId(); while( isRunning) { List<BluetoothGattService> gattServices = BluetoothLeService.this.getSupportedGattServices(); if (gattServices != null && gattServices.size() > 0) { BluetoothGattCharacteristic characteristic = getCharacteristic(gattServices); if (characteristic != null && (characteristic.getProperties() & 2) > 0) { BluetoothLeService.this.readCharacteristic(characteristic); } } } } catch(Exception e) { isRunning= false; e.printStackTrace(); } } public void kill() { this.isRunning = false; } } 

And upon successful discovery of services, I call:

 public void startReadingCharacteristics() { System.out.println("BluetoothLeService.startReadingCharacteristics"); this.mBackgroundRunnable = new BackgroundRunnableForRead(); mReadThread = new Thread(mBackgroundRunnable); mReadThread.start(); } 

And it's my characteristics to read the callback -

 public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { System.out.println("BluetoothLeService.onCharacteristicRead" + status); if (status == BluetoothGatt.GATT_SUCCESS) { broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic); } } 

The app works great on Nexus 5, Nexus 4 and Motorola G.

When I run this code on Samsung S6, it does not work, onCharacteristicRead() not called.

I read that making consecutive readCharacteristics() calls can cause problems because it is waiting for onCharacteristicRead to complete.

+6
source share
1 answer

It is recommended that you only run one gatt command at a time because the commands are not stacked . Thus, you will have to implement some kind of mechanism that gets called after the next read after you get the read callback for the current one.

Keep in mind that gatt callbacks can come from different threads, but that should not be a problem if you store the read value in the callback and then run the next read from there.

0
source

All Articles