相关疑难解决方法(0)

在BLE的connectGatt中哪个正确的autoConnect标志?

我的目标是在蓝牙低功耗设备和手机之间建立自动连接.我按照示例代码找到了该行

// We want to directly connect to the device, so we are setting the autoConnect parameter to false.
mBluetoothGatt = device.connectGatt(this, false, mGattCallback);
Run Code Online (Sandbox Code Playgroud)

上面的代码表示false用于自动连接.但是,我在这里找到了API ,它说

BluetoothGatt connectGatt(上下文上下文,布尔autoConnect,BluetoothGattCallback回调,int传输)连接到此设备托管的GATT服务器.

我还尝试了两个标志:true而且false,只有true工作.我使用的是版本> = Android 5.0.代码和API之间有什么不一致吗?哪个标志是正确的?如果我想进行自动连接,是否需要注意?

这是我的代码

public boolean connect(final String address) {
    if (mBluetoothAdapter == null || address == null) {
        Log.w(TAG, "BluetoothAdapter not initialized or unspecified address.");
        return false;
    }

    // Previously connected device.  Try to reconnect.
    if (mBluetoothDeviceAddress != null && …
Run Code Online (Sandbox Code Playgroud)

android bluetooth bluetooth-lowenergy bluetooth-gatt

13
推荐指数
1
解决办法
1万
查看次数