Android BLE onConnectionUpdated()

ami*_*one 4 android bluetooth-lowenergy

我目前正在尝试确定面向 API 27 的 Android 应用程序中的当前 BLE 连接间隔。我发现的所有文档(包括许多 SO 问题)都表示这目前是不可能的,但是,在调试模式下运行我的应用程序时,将出现以下控制台消息:

D/BluetoothGatt: onConnectionUpdated() - Device=XX:XX:XX:XX:XX:XX间隔=9延迟=0 超时=600 状态=0

不幸的是,我在docs 中找不到这个回调。假设此回调未公开,我是否正确?如果是这样,我有什么方法可以访问当前的连接间隔吗?

谢谢。

Mah*_*ena 6

下面是源代码 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);
                        }
                    }
                });
            }
Run Code Online (Sandbox Code Playgroud)

您可以在BluetoothGatt.java 中归档完整的源代码


另外在服务器上的源代码是

 /**
 * 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) {
}
Run Code Online (Sandbox Code Playgroud)

这可以在BluetoothGattServerCallback.java找到

  • 您找不到它的原因是该函数具有 @Hide 注释,使其对外部类隐藏,唯一的方法是使用反射。 (3认同)