6

I'm currently trying to determine the current BLE connection interval within an Android app targeting API 27. All documentation that I've found (including many SO questions) has said that this is currently impossible, however, when running my application in debug mode, the following console message appears:

D/BluetoothGatt: onConnectionUpdated() - Device=XX:XX:XX:XX:XX:XX interval=9 latency=0 timeout=600 status=0

Unfortunately I cannot find this callback within the docs. Am I correct in assuming that this callback isn't exposed? If so, is there any way for me to access the current connection interval?

Thanks.

1 Answer 1

9

Below is the source code for onConnectionUpdated


            /**
             * Callback invoked when the given connection is updated
             * @hide
             */
            @Override
            public void onConnectionUpdated(String address, int interval, int latency,
                    int timeout, int status) {
                if (DBG) {
                    Log.d(TAG, "onConnectionUpdated() - Device=" + address
                            + " interval=" + interval + " latency=" + latency
                            + " timeout=" + timeout + " status=" + status);
                }
                if (!address.equals(mDevice.getAddress())) {
                    return;
                }
                runOrQueueCallback(new Runnable() {
                    @Override
                    public void run() {
                        final BluetoothGattCallback callback = mCallback;
                        if (callback != null) {
                            callback.onConnectionUpdated(BluetoothGatt.this, interval, latency,
                                    timeout, status);
                        }
                    }
                });
            }

You can file the complete source code in BluetoothGatt.java


Additionally on source code on the server is

 /**
 * Callback indicating the connection parameters were updated.
 *
 * @param device The remote device involved
 * @param interval Connection interval used on this connection, 1.25ms unit. Valid range is from
 * 6 (7.5ms) to 3200 (4000ms).
 * @param latency Slave latency for the connection in number of connection events. Valid range
 * is from 0 to 499
 * @param timeout Supervision timeout for this connection, in 10ms unit. Valid range is from 10
 * (0.1s) to 3200 (32s)
 * @param status {@link BluetoothGatt#GATT_SUCCESS} if the connection has been updated
 * successfully
 * @hide
 */
public void onConnectionUpdated(BluetoothDevice device, int interval, int latency, int timeout,
        int status) {
}

This can be found at BluetoothGattServerCallback.java

4
  • Just a further question: In Android studio I am working in Kotlin. When attempting to override the function, even ff I explicitly import android.bluetooth.BluetoothGatt, onConnectionUpdated() isn't recognised as a callback function. How do I resolve this?
    – amitchone
    Oct 11, 2018 at 11:21
  • 4
    The reason you can't find it is that the function has the @Hide annotation making it hidden from external classes the only way would be using reflection.
    – Annerajb
    Jan 15, 2019 at 17:25
  • @Annerajb Well, so it's not possible to handle onConnectionUpdate in our code.
    – Xengo
    Nov 19, 2021 at 13:33
  • 1.25 ms unit? Who comes up with this? =) Oh well, that explains why I was seeing a different number than expected. Aug 20, 2022 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.