安卓蓝牙 : how to detect which slave is disconnected when there are multiple slaves?

标签 android bluetooth

此站点上的许多帖子(例如 thisthisthis)讨论了如何检测 Android 上丢失的蓝牙连接。本质上,一个人可以注册 Action 的广播

  • BluetoothAdapter.ACTION_ACL_DISCONNECT_REQUESTED
  • BluetoothAdapter.ACTION_ACL_DISCONNECTED

但是,当有多个 slave 时,我如何知道其中哪个断开连接或即将断开连接?

编辑:

  1. 我的用例是一款多人游戏。
  2. BluetoothSocket 类有一个方法isConnected(),这看起来很有用,但它需要 API 级别 14 (Android 4.0) 或更高版本。

最佳答案

在 Android 中,您可以了解设备的状态。 您可以使用 android.bluetooth.BluetoothProfile界面。它提供了一个名为 public abstract List<BluetoothDevice> getDevicesMatchingConnectionStates (int[] states) 的 API 它返回所有蓝牙设备的列表。您可以指定状态,例如 STATE_CONNECTED, STATE_CONNECTING, STATE_DISCONNECTED, STATE_DISCONNECTING在参数数组中。 有关更多信息,请参阅: http://developer.android.com/reference/android/bluetooth/BluetoothProfile.html#getDevicesMatchingConnectionStates(int[])

关于安卓蓝牙 : how to detect which slave is disconnected when there are multiple slaves?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27666903/

相关文章:

android - 错误 : Could not find method annotationProcessor() for arguments

android - SeekBar 自定义 - 如何正确定位自定义 "thumb"图像?

安卓蓝牙触摸板仿真

iOS BLE 蓝牙 - 发送/接收十六进制数据

android - 检测启用/禁用蓝牙

java - 在 Camera Intent 后更新 RecyclerView.Adapter

android - 应用通用onkeylistener

java - 错误: Error parsing XML: junk after document element when i put tabs Android

java - 如何通过单击 ListView 中的项目来连接到已配对的蓝牙设备

ios - 为什么不同的蓝牙音箱在 AVAudioSession (IOS) 方面会有不同的表现