Car Messenger

車用訊息應用程式提供專為車用裝置設計的訊息功能。 與其他車輛應用程式一樣,使用者可以從啟動器啟動 Car Messenger。

車用即時通訊的新功能

有了全新的 Car Messenger 應用程式,駕駛人可以:

  • 享有專屬的訊息體驗。
  • 從啟動器啟動車用即時通訊。
  • 瀏覽開車前和開車期間收到的訊息。
  • 聆聽及回覆訊息。
  • 忽略訊息通知。
  • 發起新對話。

術語

本頁面會使用下列詞彙:

輕觸朗讀 (TTR)
使用者與訊息通知互動時,語音助理會代表使用者朗讀及回覆簡訊。

直接回覆
與「輕觸朗讀」類似,但語音助理不會朗讀訊息,而是立即提示回覆。

直接傳送
與語音助理整合,可建立新的訊息流程,並指定或不指定聯絡人。

解除綁定應用程式的優點

獨立應用程式 (例如車用版 Messenger) 具有以下優點:

  • 僅使用公開方法 (沒有隱藏 API 的平台依附元件)
  • 在 Android 平台以外開發應用程式
  • 更頻繁地發布新功能和修正問題
  • 透過 Google Play 更新應用程式

進一步瞭解未綁定的應用程式

技術詳細資料

本節說明 Car Messenger 架構。詳情請參閱「與 CarVoiceInteractionSession 整合」一文。

以電話為基礎的架構

透過藍牙配對時,系統會將資料從手機的電話資料庫同步到車輛的電話資料庫。藍牙連線中斷後,系統會從車輛的電話資料庫刪除同步資料。

這項功能是在 Android 12 中推出。主要優點包括:

  • 您可以從資料庫擷取大量使用者訊息。
  • 支援先前開車時的訊息。
  • 在 Android 手機上,使用類似的架構和 API 儲存及擷取簡訊。
  • 完全從 Android 平台解除綁定。

流程如下:

以電話為基礎的資料流 圖 1. 以電話為基礎的資料流。

以文字格式說明流程:

 1. Phone connects to car.
    |
    --> 2. SMS data transferred from phone's database to car database.
          |
          --> 3. Car Messenger retrieves data from telephony database to display on UI.
                  |
                  --> 4. User interactions prompt the voice assistant.
                  |
          <-- 5. Car Messenger receives reply action from the voice assistant.
          |
    <-- 6. SMS is marked as read in car database.
    |
 7. Reply transmitted to recipients, phone database updated with reply and read status.

我們會如何處理這些資料:

車輛訊息服務的數據用量 圖 2. 車輛即時通訊資料處理。

以文字格式說明流程:

 1. Phone connects to car.
    |
    --> 2. SMS data transferred from phone's database to car database.
          |
          --> 3. Phone disconnects from car.
                  |
                  --> 4. SMS data deleted from car telephony database.
  • 連線後,系統會使用藍牙 MAP 將資料從手機轉移到車輛。
  • 中斷連線後,系統會從車輛資料庫中刪除該手機的資料。

取得 Car Messenger

從 Google Git 取得最新的 Car Messenger 提交。

語音互動 API

車輛訊息服務會使用 CarVoiceInteractionSession API 與 Google 助理整合。以下各節將說明這些元素。

PendingIntent 模型

這些 API 會使用 PendingIntent,將已解決的 Google 助理查詢傳回 Car Messenger。

事件順序如下:

  1. Car Messenger 會呼叫 activity.showAssist(Bundle args) 啟動 Google 助理。 args 包含 API 動作及其必要參數,並視需要包含待處理意圖。

  2. 如有必要,Google 助理會擷取使用者輸入內容,並將該內容與待處理意圖封裝在一起。

  3. Google 助理會將意圖傳回給 Car Messenger。

  4. 車輛訊息服務會解析 API 動作。

標示為已讀 API 動作

當 Google 助理朗讀訊息時,系統會將 PendingIntent 傳送至 Car Messenger,並使用 VOICE_ACTION_READ_NOTIFICATIONVOICE_ACTION_READ_CONVERSATION 動作將訊息標示為已讀。

Direct Reply API 動作

當 Google 助理回覆訊息時,系統會將 PendingIntent 連同動作 VOICE_ACTION_REPLY_NOTIFICATIONVOICE_ACTION_REPLY_CONVERSATION 傳送至 Car Messenger,以回覆對話。

直接傳送簡訊 API 動作

Car Messenger 會將包含 VOICE_ACTION_SEND_SMS 動作的組合傳送至助理。

程式碼範例:

/**
 *   KEY_PHONE_NUMBER - Recipients phone number. If this and the recipients name are not
 *   provided by the application, assistant must do contact disambiguation but is not required
 *   to add the name to the PendingIntent.
 *
 *   KEY_RECIPIENT_NAME - Recipients name. If this and the recipient phone number are not
 *   provided by the application, assistant must do contact disambiguation but is not required
 *   to add the name to the PendingIntent.
 *
 *   KEY_RECIPIENT_UID - Recipients UID in the ContactProvider database. Optionally provided
 *   by the application. Not required to be sent back by the assistant.
 *
 *   KEY_DEVICE_NAME - Friendly name of the device in which to send the message from. If not
 *   provided by the application, assistant must do device disambiguation but is not required
 *   to add it to PendingIntent. In V1 this is required to be sent by the application.
 *
 *   KEY_DEVICE_ADDRESS - Bluetooth device address of the device in which to send the message
 *   from. If not provided by the application, assistant must do device disambiguation and add
 *   this to the PendingIntent. In V1 this is required to be sent by the application.
 *
 *   KEY_SEND_PENDING_INTENT - @NotNull Will always be provided by the application. The
 *   application must preload the pending intent with any KEYs it provides the assistant that
 *   is also needed to send the message. (I.e if the application passes in the
 *   KEY_PHONE_NUMBER in the Bundle, the assistant can assume the application has already put
 *   this in the PendingIntent and may not re-add it to the PendingIntent).
 *
 */
public static final String KEY_PHONE_NUMBER = KEY_PHONE_NUMBER;
public static final String KEY_RECIPIENT_NAME = KEY_RECIPIENT_NAME;
public static final String KEY_RECIPIENT_UID = KEY_RECIPIENT_UID;
public static final String KEY_DEVICE_NAME = KEY_DEVICE_NAME;
public static final String KEY_DEVICE_ADDRESS = KEY_DEVICE_NAME;
public static final String KEY_SEND_PENDING_INTENT =KEY_SEND_PENDING_INTENT;

這張圖片顯示選取收件者後撰寫訊息的畫面:

「撥號」應用程式的「聯絡人」頁面 圖 3. 撥號應用程式中的「聯絡人」頁面。

這張圖片顯示使用「新訊息」撰寫訊息,但未選取收件者時的畫面:

未選取任何收件者 圖 4. Messenger 應用程式中的「新訊息」按鈕。

整合直接傳送簡訊動作

以下是整合 VOICE_ACTION_SEND_SMS 的撥號器範例,提供選用參數:

    /**
     * Build the {@link Bundle} to pass to assistant to send a sms.
     */
    public Bundle buildDirectSendBundle(String number, String name, String uid,
                                        BluetoothDevice device) {
        Bundle bundle = new Bundle();
        bundle.putString(CarVoiceInteractionSession.KEY_ACTION, VOICE_ACTION_SEND_SMS);
        // start optional parameters
        bundle.putString(CarVoiceInteractionSession.KEY_PHONE_NUMBER, number);
        bundle.putString(CarVoiceInteractionSession.KEY_RECIPIENT_NAME, name);
        bundle.putString(CarVoiceInteractionSession.KEY_RECIPIENT_UID, uid);
        // end optional parameters
        bundle.putString(CarVoiceInteractionSession.KEY_DEVICE_ADDRESS, device.getAddress());
        bundle.putString(CarVoiceInteractionSession.KEY_DEVICE_NAME,
                DialerUtils.getDeviceName(mContext, device));
        Intent intent = new Intent(mContext, MessagingService.class)
                .setAction(ACTION_DIRECT_SEND)
                .setClass(mContext, MessagingService.class);

        int requestCode = ACTION_DIRECT_SEND.hashCode();
        PendingIntent pendingIntent = PendingIntent.getForegroundService(
                mContext, requestCode, intent,
                PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE);

        bundle.putParcelable(KEY_SEND_PENDING_INTENT, pendingIntent);
        return bundle;
    }

改善 TTR 和直接回覆功能

更新後的 API 現在使用多功能的 Conversation 類別,可執行通知領域以外的作業,並在應用程式環境中擴充功能。這項做法會取代先前使用 StatusBarNotification 類別的規定。

偵錯車輛訊息服務

如要進一步瞭解如何偵錯車輛訊息,請參閱下列各節。

偵錯藍牙連線

  1. 執行 dumpsys 指令:

    adb shell dumpsys bluetooth_manager
    • 在 dumpsys 指令輸出中搜尋 MapClientService
     Profile: MapClientService
          mCurrentDevice: 99:99 (Pixel XL) name=Mce state=Connected
    
  2. 確認列出的裝置正確無誤。例如:

    裝置清單 圖 5. 裝置清單。

  3. 如果找不到任何裝置,請執行下列其中一項操作:

    • 重新連線藍牙。

    • 在「藍牙設定」中,確認「訊息」已開啟。

    • 在手機上確認已授予「訊息存取權」

偵錯藍牙資料庫

車輛訊息服務是以電話資料庫為基礎建構而成,如要判斷藍牙是否正在填入該資料庫,可以使用表格中的指令。

工作 指令
對話 adb shell content query --uri content://mms-sms/conversations?simple=true
僅限 SMS 訊息 adb shell content query --uri content://sms
多媒體訊息/簡訊 adb shell content query --uri content://mms-sms/conversations
僅限多媒體訊息 adb shell content query --uri content://mms
僅限多媒體訊息收件匣 adb shell content query --uri content://mms/conversations/inbox
僅傳送簡訊 adb shell content query --uri content://sms/sent
僅限簡訊收件匣 adb shell content query --uri content://sms/conversations/inbox
多媒體訊息第 1 部分
(將 1 替換成多媒體訊息的 ID)
adb shell content query --uri content://mms/part/1

偵錯 Car Messenger 和語音助理查詢

如果建構映像檔為 enguserdebug,系統會依預設列印記錄。 如要啟用 Car Messenger 的記錄功能,請按照下列步驟操作:

  1. 針對相關標記執行 adb shell setprop log.tag.<TAG> DEBUG

  2. 啟用「預先載入的 Google 助理」記錄功能。

  3. 如為高度可重現的錯誤,建議使用 Android Studio 設定中斷點。