Search code examples
androidbluetooth-lowenergyandroid-bluetoothbluetooth-gattandroid-ble

Why Android BLE gatt callback method onCharacteristicChanged callback is called in lower rate in Wear OS device than on smartphone?


I develop an application designed for Wear OS devices that received data using BLE as Gatt client. I set the mtu size the maximum possible (517 bytes), and need to transfer some large amount of data - so I set the connection priority to BluetoothGatt.CONNECTION_PRIORITY_HIGH and from the logs I see the interval is set to 5ms. I tested my app on Suunto 7 and also on Galaxy S9+ to see the BLE speed on both watch and smartphone and found out that when I get notifications from the Gatt server device I see that on Suunto 7 the onCharacteristicChanged callback is called around every 50ms, while on Galaxy S9+ the onCharacteristicChanged callback is called around every 5ms. What might cause this difference and how can I make the onCharacteristicChanged callback to be called more often on Wear OS devices? if it matters - the Gatt server device is also an android app I develop using BluetoothGattServer class and I send the data using notifications and not indications.


Solution

  • I think it's natural that you see the different delay in different device, because Galaxy S9+ has 5.0, A2DP, LE connection feature but Suunto 7 is a small device with hardware limitations.

    but if you want to fix this and get data in the same delay, you can add 45ms delay when Galaxy S9+ connected. First, you should get the device name in onCharacteristicChanged callback:

     if(gatt.getDevice().getName().equals("Galaxy S9+")){
        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
           @Override
           public void run() {
           //run function
          }
        }, 45);
                        
      }
    
     else
    
       //run function