【问题标题】:How to detect if phone is connected to Android Auto如何检测手机是否连接到 Android Auto
【发布时间】:2022-03-08 00:14:24
【问题描述】:

我正在制作一个应在手机连接到 Android Auto 时改变其行为的应用。它没有任何 Auto 功能,不会作为 Android Auto 应用进行营销/提交。

有没有办法检测手机是否连接到 Android Auto?我知道自动媒体应用程序可以通过为com.google.android.gms.car.media.STATUS 操作注册的BroadcastReceiver 检测其连接状态。 documentation 不是 100% 明确的,那么这是否也适用于所有其他非汽车应用程序?

【问题讨论】:

    标签: android android-auto


    【解决方案1】:

    编辑:在 Android 12 中,该解决方案不再适用,最好使用 CarConnection API 记录的 here

    我知道这是一个旧线程,但由于它首先出现在 Google,here is the answer from another question

    public static boolean isCarUiMode(Context c) {
    UiModeManager uiModeManager = (UiModeManager) c.getSystemService(Context.UI_MODE_SERVICE);
    if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_CAR) {
        LogHelper.d(TAG, "Running in Car mode");
        return true;
    } else {
        LogHelper.d(TAG, "Running on a non-Car mode");
        return false;
    }
    

    }

    【讨论】:

    • 感谢您的信息。对于其他 SO 答案,评论中提到了一个小问题。
    • 这在 Android 12 上不再有效。结果总是得到 1,即 UI_MODE_TYPE_NORMAL。它在 Android 11 上运行,但在 Android 12 上出现问题。我们如何解决这个问题?
    • @ArdaÇ。您需要使用 CarConnection API,我会更新我的答案,感谢您指出这一点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-10
    • 2013-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-17
    • 2010-11-17
    相关资源
    最近更新 更多