在 Android Automotive OS 上測試導航應用程式意圖

在 Android Automotive OS 上,測試 Google 助理和 Google 地圖與自訂應用程式的互通性。

總覽

本指南說明如何設定及執行內建 Google 服務的 Android Automotive 執行個體。本指南也會說明如何測試第三方 Google API,以便搭配導航和語音解決方案使用。

如要進一步瞭解這些 API,請參閱「導入導航應用程式意圖」和「Android Automotive 版 Google 地圖意圖」。

意圖資料流程

如圖所示,您可以使用三種意圖描述 Google 助理與導覽之間的互動:導覽、搜尋和自訂動作。本文說明如何使用 Google 地圖測試意圖。我們也說明如何整合自訂導覽應用程式,接收 Google 助理傳送的意圖。

設定

做法如下:

  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」,在模擬器中安裝並啟動試用版應用程式。

試用

導入導航應用程式意圖Android Automotive 意圖適用的 Google 地圖說明瞭您可以執行的三種意圖:導航、搜尋和自訂動作。

試用版應用程式的主要活動
示範應用程式的主要活動

Google 地圖會執行觸發的操作。

如要將示範應用程式指定為 Google 助理觸發意圖的接收者,請按照下列步驟操作:

  1. 依序前往「設定」>「Google」>「Google 助理」>「預設導航應用程式」

    選取預設導航應用程式
    圖 1. 選取預設導航應用程式。
  2. 按一下「麥克風」圖示,然後說出查詢內容。例如「附近的餐廳」。如果麥克風無法正常運作,請參閱「擴充控制項、設定和說明」。Google 助理會將意圖 URI 傳送至導航應用程式,以進行後續處理。

    Google 助理產生的意圖輸出內容
    圖 2. Google 助理產生的意圖輸出內容。

技術詳細資料

您可以使用 Android Debug Bridge (adb) 從控制台觸發意圖。詳情請參閱 gas-intents-console-tests.txt

如要指定應用程式可接收 Google 助理的意圖,請在導覽應用程式的 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>