Car Messenger 提供專為汽車設備設計的訊息傳遞功能。與其他汽車應用程式一樣,用戶從啟動器啟動 Car Messenger。
汽車信差有什麼新功能?
借助新的 Car Messenger 應用程序,駕駛員可以:
- 獲得專門的訊息傳遞體驗。
- 從啟動器啟動汽車信差。
- 瀏覽駕駛前和駕駛過程中收到的訊息。
- 收聽並回覆訊息。
- 靜音訊息通知。
- 開始新的對話。
術語
本頁使用這些術語:
非捆綁應用程式的好處
非捆綁應用程式(例如 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。
這是事件的順序:
Car Messenger 透過呼叫
activity.showAssist(Bundle args)
啟動助手。 args 包含 API 操作及其所需參數,如果需要,也包含待處理的意圖。如有必要,Assistant 會檢索使用者輸入,並將其與待處理意圖打包。
Assistant 將意圖傳回 Car Messenger。
Car Messenger解析API 操作。
標記為已讀 API 操作
當助手正在閱讀訊息時, PendingIntent
會透過操作VOICE_ACTION_READ_NOTIFICATION
或VOICE_ACTION_READ_CONVERSATION
傳送到 Car Messenger,以將訊息標記為已讀。
直接回覆 API 操作
當助理回覆訊息時, PendingIntent
會透過操作VOICE_ACTION_REPLY_NOTIFICATION
和VOICE_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 的更多資訊。
調試藍牙連接
運行
dumpsys
命令:adb shell dumpsys bluetooth_manager
- 在 dumpsys 命令輸出中搜尋
MapClientService
。
Profile: MapClientService mCurrentDevice: 99:99 (Pixel XL) name=Mce state=Connected
- 在 dumpsys 命令輸出中搜尋
確認列出了正確的設備。例如:
圖 5.設備列表。
如果未找到設備,請執行下列其中一項操作:
- 重新連線至藍牙。
或者
- 在藍牙設定中,確認簡訊已開啟。
或者
- 在電話上,確認已授予訊息存取權限。
調試藍牙資料庫
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 和語音助理查詢
如果建置映像是eng
或userdebug
則預設列印日誌。否則,要啟用 Car Messenger 的日誌記錄:
運行相關標籤
adb shell setprop log.tag.<TAG> DEBUG
。為Preloaded Assistant啟用日誌記錄。
對於高度可重現的錯誤,請考慮在Android Studio中使用斷點。