对于找到的蓝牙设备,我们通过操作从 Android 接收 Brodcast:
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// New bluetooth device found
}
当我们将设备设置为能够发现时,就会发生这种情况。
我的问题是,当设备可发现功能关闭或其他设备的蓝牙关闭时,触发的 Intent 是什么。
在我的 ListView 中,我显示了“已找到”的设备,我可以使用上面的代码来执行此操作。但我想删除不再在范围内、不再可发现或已关闭蓝牙的设备条目,Android 平台是否有任何特定的 Intent ?
我查看了 BluetoothDevice
、BluetoothAdapter
引用 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_STATE
- 当前连接状态。 -
EXTRA_PREVIOUS_CONNECTION_STATE
- 先前的连接状态。 - EXTRA_DEVICE - 远程设备。
关于java - 如何检测蓝牙设备是否超出范围,或者我们丢失了它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30844519/