在 Android Automotive OS 上测试导航应用 intent

测试 Google 助理和 Google 地图与 Android Automotive OS 上自定义应用的互操作性。

概览

本指南介绍了如何设置和运行内置 Google 的 Android Automotive 实例。本指南还介绍了如何测试第三方 Google API 以用于导航和语音解决方案。

如需详细了解这些 API,请参阅实现导航应用 intentGoogle 地图 Android Automotive 版 intent

意图数据流

如上所示,您可以使用三种类型的 intent 来描述助理与导航之间的互动:导航、搜索和自定义操作。此内容介绍了如何使用 Google 地图测试 intent。我们还介绍了如何集成自定义导航应用以接收来自 Google 助理的 intent。

设置

如需使用此功能,请按下列步骤操作:

  1. 下载并安装 Android Studio
  2. 依次打开 Tools > Device Manager,然后添加 Automotive (1408p landscape) with Google Play 映像。
  3. 启动模拟器映像并登录 Google Play。搜索并更新 Google 助理。
  4. 提取我们的演示应用项目的内容,然后在 Android Studio 中打开该项目(File > Open...)。
  5. 选择 Run > Run automotive 以在模拟器中安装并启动演示应用。

演示

实现导航应用 intentGoogle Maps for Android Automotive intent 介绍了您可以执行的三种类型的 intent:导航、搜索和自定义操作。

演示应用的主要 activity
演示应用的主要 activity

Google 地图会执行触发的操作。

如需将演示版应用指定为由 Google 助理触发的 intent 的接收方,请执行以下操作:

  1. 依次前往设置 > Google > Google 助理 > 默认导航应用

    选择默认导航应用
    图 1. 选择默认导航应用。
  2. 点击麦克风图标,然后说出查询内容。例如“附近的餐厅”。如果麦克风无法正常工作,请参阅扩展控件、设置和帮助。 intent URI 由 Google 助理发送到导航应用以进行进一步处理。

    Google 助理生成的 intent 的输出
    图 2. Google 助理生成的 intent 的输出。

技术详情

您可以使用 Android 调试桥 (adb) 从控制台触发 intent。如需了解详情,请参阅 gas-intents-console-tests.txt

如需指定应用可以接收来自 Google 助理的 intent,请在导航应用的 AndroidManifest.xml 文件中添加以下代码:

   <!-- Navigation Intent -->
    <intent-filter>
      <action android:name="androidx.car.app.action.NAVIGATE" />
      <category android:name="android.intent.category.DEFAULT"/>
      <data android:scheme="geo" />
    </intent-filter>

    <!-- Search Intent -->
    <intent-filter>
      <action android:name="android.intent.action.VIEW" />
      <category android:name="android.intent.category.DEFAULT"/>
      <data android:scheme="geo" />
    </intent-filter>

    <!-- Custom Action Intents -->
    <intent-filter>
      <action android:name="android.intent.action.VIEW" />
      <category android:name="android.intent.category.DEFAULT"/>
      <data android:scheme="geo.action" />
    </intent-filter>

如需将应用添加到设置 > Google > Google 助理 > 默认导航应用,以便用户可以查看和选择该应用,请添加:

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.APP_MAPS" />
    </intent-filter>