汽車信使

Car Messenger 提供專為汽車設備設計的訊息傳遞功能。與其他汽車應用程式一樣,用戶從啟動器啟動 Car Messenger。

汽車信差有什麼新功能?

借助新的 Car Messenger 應用程序,駕駛員可以:

  • 獲得專門的訊息傳遞體驗。
  • 從啟動器啟動汽車信差。
  • 瀏覽駕駛前和駕駛過程中收到的訊息。
  • 收聽並回覆訊息。
  • 靜音訊息通知。
  • 開始新的對話​​。

術語

本頁使用這些術語:

點擊閱讀 (TTR)
當用戶與訊息通知互動時,點擊閱讀使語音助理能夠代表該用戶閱讀和回覆簡訊。

直接回覆
與點擊閱讀類似,不同之處在於語音助理不會讀出訊息並立即發出回應提示。

直接發送
與語音助理集成,以編寫包含或不包含指定聯絡人的新訊息流。

非捆綁應用程式的好處

非捆綁應用程式(例如 Car Messenger)具有以下優勢:

  • 僅使用公共方法(不依賴隱藏 API 的平台)
  • 開發Android平台以外的應用程式
  • 啟用更頻繁的發布(針對新功能和已修復的問題)
  • 透過 Google Play 更新應用程式

了解有關非捆綁應用程式的更多資訊。

技術細節

本節介紹 Car Messenger 架構。要了解更多信息,請參閱與 CarVoiceInteractionSession 整合

基於電話的架構

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

此功能是在 Android 12 中引入的。主要優點包括:

  • 可以從資料庫中檢索批次用​​戶訊息。
  • 支援來自先前驅動器的消息。
  • 使用類似的架構和 API 在 Android 手機上進行 SMS 儲存和檢索。
  • 與 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. Car Messenger 資料處理。

以文字格式說明的流程:

 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 從手機傳輸到汽車。
  • 斷開連接後,該手機的資料將從汽車資料庫中刪除。

取得汽車信使

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

語音互動API

Car Messenger 使用CarVoiceInteractionSession API 與助理整合。以下各節將介紹這些元素。

待定意圖模型

這些 API 使用PendingIntent將已解析的助理查詢傳回 Car Messenger。

這是事件的順序:

  1. Car Messenger 透過呼叫activity.showAssist(Bundle args)啟動助手。 args 包含 API 操作及其所需參數,如果需要,也包含待處理的意圖。

  2. 如有必要,Assistant 會檢索使用者輸入,並將其與待處理意圖打包。

  3. Assistant 將意圖傳回 Car Messenger。

  4. Car Messenger解析API 操作。

標記為已讀 API 操作

當助手正在閱讀訊息時, PendingIntent會透過操作VOICE_ACTION_READ_NOTIFICATIONVOICE_ACTION_READ_CONVERSATION傳送到 Car Messenger,以將訊息標記為已讀。

直接回覆 API 操作

當助理回覆訊息時, PendingIntent會透過操作VOICE_ACTION_REPLY_NOTIFICATIONVOICE_ACTION_REPLY_CONVERSATION傳送到 Car Messenger,以回覆對話。

直接發送簡訊 API 操作

包含VOICE_ACTION_SEND_SMS作業的套裝組合將從 Car Messenger 傳送到助理。

範例程式碼:

/**
 *   KEY_PHONE_NUMBER - Recipient’s 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 - Recipient’s 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 - Recipient’s 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. Dialer 應用程式中的聯絡人頁面。

此圖顯示了在未選擇收件人的情況下使用新訊息撰寫訊息:

沒有選定的收件人圖 4. Messenger 應用程式中的「新訊息」按鈕。

整合直接發送簡訊操作

以下是 Dialer 整合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類別的要求。

調試汽車信使

請參閱以下部分,以了解有關調試 Car Messenger 的更多資訊。

調試藍牙連接

  1. 運行dumpsys命令:

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

    設備列表圖 5.設備列表。

  3. 如果未找到設備,請執行下列其中一項操作

    • 重新連線至藍牙。

    或者

    • 藍牙設定中,確認簡訊已開啟。

    或者

    • 在電話上,確認已授予訊息存取權限

調試藍牙資料庫

Car Messenger 是建立在電話資料庫之上的。若要確定藍牙是否正在填入該資料庫,您可以使用表中的命令。

任務命令
對話adb shell content query--uri content://mms-sms/conversations?simple=true
僅短信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. Preloaded Assistant啟用日誌記錄。

  3. 對於高度可重現的錯誤,請考慮在Android Studio中使用斷點。