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();将返回经典设备和btle设备。有人知道什么是正确的吗?
发布于 2014-07-31 22:13:16
根据我的理解,文档的意思是不能同时运行startLeScan()和startDiscovery()。原因可能是只有一个BluetoothAdapter对象(表示本地蓝牙硬件的对象),它不能同时执行两个使用BluetoothAdapter的不同操作(如果有人知道它在后台的工作方式有什么不同,请告诉我们)
startLeScan() ->只扫描BLE设备
startDiscovery() ->发现所有蓝牙设备,而且它只扫描12秒,这是不能更改的(通过方法描述进行读取)
注意:当发现BT设备时,在执行startDiscovery()查询扫描之后,您可以获得设备类型以确定每个设备是什么,例如:
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) {
}发布于 2021-03-22 18:35:50
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"
}https://stackoverflow.com/questions/25065810
复制相似问题