【发布时间】: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