首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android蓝牙扫描经典和BTLE设备

Android蓝牙扫描经典和BTLE设备
EN

Stack Overflow用户
提问于 2014-07-31 17:55:39
回答 2查看 5.5K关注 0票数 7

android 文档声明:

代码语言:javascript
复制
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设备。有人知道什么是正确的吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-07-31 22:13:16

根据我的理解,文档的意思是不能同时运行startLeScan()startDiscovery()。原因可能是只有一个BluetoothAdapter对象(表示本地蓝牙硬件的对象),它不能同时执行两个使用BluetoothAdapter的不同操作(如果有人知道它在后台的工作方式有什么不同,请告诉我们)

startLeScan() ->只扫描BLE设备

startDiscovery() ->发现所有蓝牙设备,而且它只扫描12秒,这是不能更改的(通过方法描述进行读取)

注意:当发现BT设备时,在执行startDiscovery()查询扫描之后,您可以获得设备类型以确定每个设备是什么,例如:

代码语言:javascript
复制
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) {
            
}
票数 14
EN

Stack Overflow用户

发布于 2021-03-22 18:35:50

代码语言:javascript
复制
           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"
            }
票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25065810

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档