安卓蓝牙扫描经典和低功耗设备

7

Android的文档中提到:

Note: You can only scan for Bluetooth LE devices or scan for Classic Bluetooth devices, as described in Bluetooth. You cannot scan for both Bluetooth LE and classic devices at the same time.

然而我注意到调用mBtAdapter.startDiscovery();后返回的是经典蓝牙和BLE设备。有没有人知道这里哪个是正确的?
2个回答

14
根据我的理解,文档的意思是您不能同时运行startLeScan()startDiscovery()。原因可能是只有一个BluetoothAdapter对象(表示本地蓝牙硬件的对象),因此它不能同时执行使用BluetoothAdapter的两个不同操作。(如果有人知道背景下的工作方式有什么不同,请告诉我们)
startLeScan() -> 仅扫描BLE设备
startDiscovery() -> 发现所有蓝牙设备,还仅扫描12秒,这无法更改(请阅读方法说明) 注意:在进行startDiscovery()查询扫描后,当发现BT设备时,可以获取设备类型以识别每个设备,例如:
int deviceType = device.getType();
if (deviceType == BluetoothDevice.DEVICE_TYPE_CLASSIC) {

} else if (deviceType == BluetoothDevice.DEVICE_TYPE_LE) {

} else if (deviceType == BluetoothDevice.DEVICE_TYPE_DUAL) {    

} else if (deviceType == BluetoothDevice.DEVICE_TYPE_UNKNOWN) {
            
}

听起来文档有误。我刚刚使用startDiscovery()进行了扫描,它返回了经典、LE和双模设备。 - ThomasW
1
经过进一步调查,我发现虽然 startDiscovery() 可以找到 BLE 设备,但是 startLeScan() 更可靠地找到它们。 - ThomasW
@ThomasW,startDiscovery() 可以找到所有设备,而只有 startLeScan() 能够看到 BLE 设备。 - KikiTheMonk

-2
           device: BluetoothDevice

           when (device.type) {
                1 -> edt.text = "DEVICE_TYPE_CLASSIC"
                2 -> edt.text = "DEVICE_TYPE_LE"
                3 -> edt.text = "DEVICE_TYPE_DUAL"
                else -> edt.text = "DEVICE_TYPE_UNKNOWN"
            }

这并没有真正回答被问出来的问题... - Hack5

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接