Android 4.4:低功耗蓝牙;无需扫描 BLE 设备即可连接 [英] Android 4.4: Bluetooth Low Energy; Connect without scanning for a BLE device

查看:35
本文介绍了Android 4.4:低功耗蓝牙;无需扫描 BLE 设备即可连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序应连接到蓝牙 LE 设备.通常您使用 mBluetoothAdapter.startLeScan(mLeScanCallback); 执行设备扫描.回调为您提供有关可用设备的信息.

my app shall connect to a Bluetooth LE device. Usually you perform a device scan using mBluetoothAdapter.startLeScan(mLeScanCallback);. The callback provides you information about available devices.

如果你想连接到一个专用设备,你可以做一些类似的事情

If you want to connect to a dedicated device, you do something like

BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);

然后

mBluetoothGatt = device.connectGatt(this, false, mGattCallback);

在我看来,连接到 BLE 设备唯一需要的是知道 BLE 地址,然后通过上述两个步骤连接到它.因此,如果我已经知道 BLE 地址(例如,它写在 BLE 设备的标签上),我就不需要执行 BLE 扫描.

To me it looks like the only thing you need to connect to a BLE device, is to know the BLE address and then connect to it with the above two steps. So if I know a BLE address already (e.g. it is written on the label of the BLE device) I don’t need to perform a BLE scan.

但我遇到的是,如果我有一个以前从未通过 BLE 扫描找到的 BLE 设备,则无法使用其 BLE 地址直接连接到它.我必须用我的安卓手机至少扫描一次才能找到它.之后我再也不需要扫描了,我只需使用它的 BLE 地址就可以连接到 BLE 设备.

But what I have encountered is, that if I have a BLE device which I have never found through a BLE scan before, it is not possible to connect to it directly in using its BLE address. I have to find it through a scan at least one time with my android phone. Afterwards I never need a scan again and I can connect to the BLE device just by using its BLE address.

应该是这样还是我监督了什么?

Is it supposed to be like this or did I oversee something?

非常感谢,斯蒂芬

推荐答案

设备地址只是蓝牙设备的唯一标识,不包含连接信息.扫描对于从蓝牙设备检索广播信号中的信息是必要的,以便可以建立连接.扫描完成后,信息会保存在设备上的某处并绑定到设备地址.

The device address is merely a unique identifier for the bluetooth device, it doesn't contain the information for connection. The scan is necessary to retrieve the information within the broadcast signal from the bluetooth device so that a connection can be made. Once the scan is done, the information is saved somewhere on the device and bound to the device address.

我认为,如果您尝试检索蓝牙地址的值,它将返回 null,直到它被扫描一次.

I think if you try to retrieve the value for the bluetooth address it will return null until after it has been scanned once.

这篇关于Android 4.4:低功耗蓝牙;无需扫描 BLE 设备即可连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆