【问题标题】:Find all Bluetooth Devices within range of the phone查找手机范围内的所有蓝牙设备
【发布时间】:2021-06-08 05:26:51
【问题描述】:

我知道我可以使用BluetoothAdapter.startDiscovery() 发现新设备 IntentFilter(BluetoothDevice.ACTION_FOUND)BroadcastReceiver

并通过BluetoothAdapter.getBondedDevices()获取所有配对的蓝牙设备。

但如果我配对一个设备,我不知道它是否可以访问。

有没有办法让所有设备都在手机的范围内?我什至不需要BluetoothDevice 对象,我不会联系他们,我只想要他们的地址。

【问题讨论】:

    标签: android bluetooth android-bluetooth


    【解决方案1】:

    您可以从找到的设备的阵列/列表中排除绑定的设备。 像这样的:

    if (device.bondState != BluetoothDevice.BOND_BONDED) { 
           mDevicesArrayAdapter.add(device.name + "\n" + device.address)
    }
    

    【讨论】:

    • 这不是我想要的。我可以使用BluetoothAdapter.startDiscovery() 发现的唯一设备是未绑定的设备。我还需要一种方法来发现手机可触及的绑定对象。
    • 当您调用 startDiscovery 时,您将获得新设备和绑定设备。来自文档:Find devices Using the BluetoothAdapter, you can find remote Bluetooth devices either through device discovery or by querying the list of paired devices. Device discovery is a scanning procedure that searches the local area for Bluetooth-enabled devices and requests some information about each one. 还有:Query paired devices Before performing device discovery, it's worth querying the set of paired devices to see if the desired device is already known.
    • 好吧,不幸的是,我只能通过这种方式获得新设备。也许我做错了什么。还是谢谢。
    • 没问题,如果您需要帮助,请发布一些代码
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-18
    • 1970-01-01
    • 2014-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多