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

标签 java android android-intent bluetooth broadcastreceiver

对于找到的蓝牙设备,我们通过操作从 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/

相关文章:

android - 使 Activity A 等待 Activity B 完成以继续

java - 主细节流程版本支持

java - Eclipse 导航器上下文菜单

java - 在类中的所有 setter 上使用 Spring @Autowired

java - 如何为我的 Web 应用程序设置到期日期?

Android Room Kotlin 抛出删除查询错误

android - getSerializableExtra() 随机为 null

通过套接字进行 Java 加密对象序列化

java - 尝试修改 Activity 的后退按钮

android - 在 Android API 22 中打开相机灯