看官们,我们在上一章回中介绍了BLE开发中蓝牙扫描设备的例子,本章回中我们继续介绍该例子,闲话休提,言归正转。让我们一起Talk Android吧!
我们在上一章回中介绍了BluetoothLeScanner类的startScan方法,本章回中介绍该方法的第一个参数:filters,该参数是ScanFilter类型的List.该参数的主要作用是用来过滤蓝牙设备,这点和前面章回中提到的UUID一样。不过它提供的过滤条件更加丰富,官方给出的条件有以下五个:
- UUID
- 蓝牙设备名
- 蓝牙设备MAC地址
- 服务包含的数据
- 厂商提供的特殊数据;
下面是官方文档中的说明:
Current filtering on the following fields are supported: Service UUIDs which identify the bluetooth gatt services running on the device. Name of remote Bluetooth LE device. Mac address of the remote
device. Service data which is the data associated with a service.
Manufacturer specific data which is the data associated with a particular manufacturer.
我在代码中使用了设备名称来当作过滤条件,示例代码如下:
List<ScanFilter> filters

本文详细介绍了Android中BluetoothLeScanner的startScan方法中的ScanFilter参数,用于过滤蓝牙设备。通过示例代码展示了如何使用设备名称和UUID作为过滤条件,并指出设备名称过滤时不支持正则表达式,而UUID过滤则能有效匹配蓝牙设备。同时,讨论了源代码中的实现细节,确认了过滤过程基于ScanFilter的equals方法。鼓励读者自行实验其他过滤条件以加深理解。
最低0.47元/天 解锁文章
291

被折叠的 条评论
为什么被折叠?



