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

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

问题描述

我的应用程序应连接到Bluetooth 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设备的标签上),则无需执行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地址直接连接到它.我必须使用Android手机至少扫描一次才能找到它.之后,我再也不需要扫描,只需使用其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.

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

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天全站免登陆