【问题标题】:STATE_CONNECTED doesn't mean it's really CONNECTED?STATE_CONNECTED 并不意味着它真的是 CONNECTED?
【发布时间】:2020-12-14 04:26:25
【问题描述】:

如果我们看一下this,它会说:

Android支持一个连接的蓝牙耳机同时 时间

还有getConnectedDevices()的解释:

返回状态为STATE_CONNECTED的设备集合

方法的返回类型是List<BluetoothDevice>,在我的例子中它返回多个。 一款用于 Galaxy Watch,一款用于 Galaxy Buds。

我知道如何判断当前哪个处于活动状态。 当BluetoothHeadset.isAudioConnected() 被调用时,当前使用的那个将返回true。 所以我不是在问如何在这里找到活动的蓝牙耳机设备。 我更想了解STATE_CONNECTED 的真正含义。

我认为这对其他人也很有用,因为有很多类似以下的答案,在某些情况下不会按预期工作:

public static boolean isConnected() {
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    return  bluetoothAdapter != null
        && bluetoothAdapter.isEnabled()
        && bluetoothAdapter.getProfileConnectionState(BluetoothProfile.HEADSET) == BluetoothProfile.STATE_CONNECTED;
}

如果您只是想检查您的用户是否在打电话,这不是正确的。 这是因为用户的蓝牙耳机在打开蓝牙耳机并与智能手机同步后会立即变为STATE_CONNECTED

那么,STATE_CONNECTED 到底是什么?

【问题讨论】:

    标签: android bluetooth android-bluetooth bluetoothadapter bluetoothheadset


    【解决方案1】:

    根据文档,bluetoothAdapter.getProfileConnectionState(BluetoothProfile.HEADSET) 返回BluetoothProfile.HEADSET 配置文件的当前连接状态。

    如果手机的蓝牙适配器当前连接到具有耳机配置文件的设备,则此调用返回BluetoothProfile.STATE_CONNECTED

    这并不意味着用户当前正在使用耳机通话。这意味着耳机已准备好处理与手机的通信。

    【讨论】:

      猜你喜欢
      • 2018-05-12
      • 1970-01-01
      • 2014-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多