如何识别我的 Android 设备何时通过蓝牙连接到汽车系统

How to identify when my Android device is connected to the system of a car via Bluetooth

我想知道在检查我的设备是否通过蓝牙连接到汽车系统时是否有任何特定的 callback 或类似的东西。

我知道有些公司在连接到这些系统时会更改 UI。比方说,UI 用于无蓝牙连接或蓝牙连接时佩戴耳机与完全不同的 UI 连接到汽车时(例如非常大的按钮,可以在驾驶时轻松点击)

我从 Android 看了 BluetoothAdapter。我特别感兴趣的是 ACTION_CONNECTION_STATE_CHANGED ,它可以让我知道何时建立了新连接,但我并没有真正看到任何方法来识别何时连接到汽车或任何其他蓝牙设备的系统。

还有其他方法吗?如果是这样,请提供一个简单的实现或 link 好的文档。

我按照评论中提出的问题按状态过滤蓝牙连接(在这种情况下,我对已连接的连接感兴趣)。

public class BluetoothServiceListener implements BluetoothProfile.ServiceListener {
    private String TAG = "bluetoothListener";
    private static final int[] states={
            BluetoothProfile.STATE_CONNECTED};
    @Override
    public void onServiceConnected(int profile, BluetoothProfile bluetoothProfile) {
        List<BluetoothDevice> Devices=bluetoothProfile.getDevicesMatchingConnectionStates(states);
        for (BluetoothDevice device:Devices){
            if(device.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.AUDIO_VIDEO_CAR_AUDIO);
                Log.i(TAG, "NAME | " + device.getName() + device.getBluetoothClass().getDeviceClass());
        }
    }

    @Override
    public void onServiceDisconnected(int profile) {
    }

}