gpt4 book ai didi

java - 如何检测蓝牙设备是否超出范围,或者我们丢失了它?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:23:03 25 4
gpt4 key购买 nike

对于找到的蓝牙设备,我们通过操作从 Android 接收 Brodcast:

if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// New bluetooth device found
}

当我们将设备设置为能够发现时,就会发生这种情况。

我的问题是,当设备可发现功能关闭或其他设备的蓝牙关闭时,触发的 Intent 是什么。

在我的 ListView 中,我显示了“已找到”的设备,我可以使用上面的代码来执行此操作。但我想删除不再在范围内、不再可发现或已关闭蓝牙的设备条目,Android 平台是否有任何特定的 Intent ?

我查看了 BluetoothDeviceBluetoothAdapter 引用 API。但是没有发现有用的广播 Action 。

最佳答案

您要搜索的 Intent 是BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED

Intent used to broadcast the change in connection state of the local Bluetooth adapter to a profile of the remote device.

这个 intent 会有 3 个额外的东西:

EXTRA_CONNECTION_STATEEXTRA_PREVIOUS_CONNECTION_STATE可以是:

关于java - 如何检测蓝牙设备是否超出范围,或者我们丢失了它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30844519/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com