gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 01:36:26 26 4
gpt4 key购买 nike

此站点上的许多帖子(例如 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/

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