Car Messenger มีความสามารถในการรับส่งข้อความที่ออกแบบมาสำหรับอุปกรณ์ยานยนต์ ผู้ใช้จะเริ่มใช้ Car Messenger จากตัวเรียกใช้เช่นเดียวกับแอปในรถยนต์อื่นๆ
มีอะไรใหม่ใน Car Messenger
แอป Car Messenger ใหม่ช่วยให้ผู้ขับทำสิ่งต่อไปนี้ได้
- รับประสบการณ์การรับส่งข้อความโดยเฉพาะ
- เปิด Car Messenger จาก Launcher
- เรียกดูข้อความที่ได้รับก่อนและระหว่างการขับรถ
- ฟังและตอบข้อความ
- ปิดเสียงการแจ้งเตือนข้อความ
- เริ่มการสนทนาใหม่
คำศัพท์
คำศัพท์ที่ใช้ในหน้านี้มีดังนี้
ประโยชน์ของแอปที่แยกส่วน
แอปที่แยกส่วน เช่น Car Messenger มีข้อดีดังนี้
- ใช้เฉพาะเมธอดสาธารณะ (ไม่มีการขึ้นต่อแพลตฟอร์มใน API ที่ซ่อนอยู่)
- พัฒนาแอปนอกแพลตฟอร์ม Android
- เปิดใช้การเผยแพร่ที่บ่อยขึ้น (สำหรับฟีเจอร์ใหม่และปัญหาที่แก้ไขแล้ว)
- อัปเดตแอปผ่าน Google Play
ดูข้อมูลเพิ่มเติมเกี่ยวกับแอปที่แยกจำหน่าย
รายละเอียดด้านเทคนิค
ส่วนนี้จะอธิบายสถาปัตยกรรมของ Car Messenger ดูข้อมูลเพิ่มเติมได้ที่ ผสานรวมกับ CarVoiceInteractionSession
สถาปัตยกรรมที่ใช้โทรศัพท์
เมื่อจับคู่ผ่านบลูทูธ ระบบจะซิงค์ข้อมูลจากฐานข้อมูลโทรศัพท์ของโทรศัพท์ ไปยังฐานข้อมูลโทรศัพท์ของรถยนต์ เมื่อยกเลิกการเชื่อมต่อบลูทูธ ระบบจะลบข้อมูลที่ซิงค์ออกจากฐานข้อมูลโทรศัพท์ของรถยนต์
ความสามารถนี้เปิดตัวใน Android 12 ประโยชน์หลักๆ มีดังนี้
- คุณสามารถดึงข้อมูลข้อความของผู้ใช้จำนวนมากจากฐานข้อมูลได้
- รองรับข้อความจากการขับขี่ครั้งก่อน
- ใช้สถาปัตยกรรมและ API ที่คล้ายกันสำหรับการจัดเก็บและการดึงข้อมูล SMS ในโทรศัพท์ Android
- แยกออกจากแพลตฟอร์ม 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 บลูทูธ
- เมื่อยกเลิกการเชื่อมต่อ ระบบจะลบข้อมูลของโทรศัพท์เครื่องนั้นออกจากฐานข้อมูลของรถ
ดาวน์โหลด Car Messenger
รับคอมมิต Car Messenger ล่าสุดจาก Google Git
Voice Interaction APIs
Car Messenger ใช้ API CarVoiceInteractionSession เพื่อผสานรวมกับ ผู้ช่วย เราจะอธิบายองค์ประกอบเหล่านี้ในส่วนต่อไปนี้
โมเดล PendingIntent
API เหล่านี้ใช้ PendingIntent
เพื่อส่งคำค้นหาที่ Assistant แก้ไขแล้วกลับไปที่
Car Messenger
ลำดับเหตุการณ์มีดังนี้
Car Messenger เปิดตัวผู้ช่วยโดยการโทรหา
activity.showAssist(Bundle args)
อาร์กิวเมนต์ประกอบด้วยการดำเนินการ API และพารามิเตอร์ที่จำเป็น ซึ่งมี PendingIntent หากจำเป็นAssistant จะดึงข้อมูลที่ผู้ใช้ป้อนหากจำเป็น และจัดแพ็กเกจข้อมูลดังกล่าวพร้อมกับ Intent ที่รอดำเนินการ
Assistant จะส่ง Intent กลับไปที่ Car Messenger
Car Messenger แก้ไขการดำเนินการของ API
การดำเนินการ API "ทำเครื่องหมายว่าอ่านแล้ว"
เมื่อ Assistant อ่านข้อความ ระบบจะส่ง PendingIntent
ไปยัง Car
Messenger พร้อมการดำเนินการ VOICE_ACTION_READ_NOTIFICATION
หรือ
VOICE_ACTION_READ_CONVERSATION
เพื่อทำเครื่องหมายข้อความว่าอ่านแล้ว
การดำเนินการของ Direct Reply API
เมื่อ Assistant ตอบกลับข้อความ ระบบจะส่ง PendingIntent
ไปยัง Car
Messenger พร้อมการดำเนินการ VOICE_ACTION_REPLY_NOTIFICATION
และ VOICE_ACTION_REPLY_CONVERSATION
เพื่อตอบกลับการสนทนา
การดำเนินการ Direct Send SMS 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 หน้า Contacts ในแอปแป้นโทรศัพท์
รูปภาพนี้แสดงการเขียนข้อความเมื่อไม่ได้เลือกผู้รับโดยใช้ข้อความใหม่
รูปที่ 4 ปุ่มข้อความใหม่ในแอป Messenger
ผสานรวมการดำเนินการส่ง SMS โดยตรง
ต่อไปนี้คือตัวอย่างการผสานรวมVOICE_ACTION_SEND_SMS
ใน Dialer ซึ่งมีพารามิเตอร์ที่ไม่บังคับ
/**
* 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
Debug Car Messenger
ดูข้อมูลเพิ่มเติมเกี่ยวกับการแก้ไขข้อบกพร่องของ Car Messenger ได้ในส่วนต่อไปนี้
แก้ไขข้อบกพร่องของการเชื่อมต่อบลูทูธ
เรียกใช้คำสั่ง
dumpsys
adb shell dumpsys bluetooth_manager
- ค้นหา
MapClientService
ในเอาต์พุตของคำสั่ง dumpsys
Profile: MapClientService mCurrentDevice: 99:99 (Pixel XL) name=Mce state=Connected
- ค้นหา
ตรวจสอบว่าอุปกรณ์ที่ถูกต้องแสดงอยู่ เช่น
รูปที่ 5 รายการอุปกรณ์
หากไม่พบอุปกรณ์ ให้ทำอย่างใดอย่างหนึ่งต่อไปนี้
- เชื่อมต่อบลูทูธอีกครั้ง
หรือ
- ในการตั้งค่าบลูทูธ ให้ตรวจสอบว่าข้อความเปิดอยู่
หรือ
- ในโทรศัพท์ ให้ยืนยันว่าได้รับสิทธิ์เข้าถึงข้อความแล้ว
แก้ไขข้อบกพร่องของฐานข้อมูลบลูทูธ
Car Messenger สร้างขึ้นบนฐานข้อมูลโทรศัพท์ หากต้องการดูว่าบลูทูธ สร้างฐานข้อมูลนั้นหรือไม่ คุณสามารถใช้คำสั่งในตารางได้
งาน | คำสั่ง |
---|---|
การสนทนา | adb shell content query --uri content://mms-sms/conversations?simple=true |
ข้อความ SMS เท่านั้น | adb shell content query --uri content://sms |
ข้อความ MMS/SMS | adb shell content query --uri content://mms-sms/conversations |
ข้อความ MMS เท่านั้น | adb shell content query --uri content://mms |
กล่องจดหมาย MMS เท่านั้น | adb shell content query --uri content://mms/conversations/inbox |
ข้อความ SMS ที่ส่งเท่านั้น | adb shell content query --uri content://sms/sent |
กล่องจดหมาย SMS เท่านั้น | adb shell content query --uri content://sms/conversations/inbox |
ข้อความ MMS ส่วนที่ 1 (แทนที่ 1 ด้วยรหัสของ MMS) |
adb shell content query --uri content://mms/part/1 |
แก้ไขข้อบกพร่องของ Car Messenger และคำค้นหาของผู้ช่วยแบบเสียง
บันทึกการพิมพ์โดยค่าเริ่มต้นหากอิมเมจบิลด์เป็น eng
หรือ userdebug
หรือหากต้องการเปิดใช้การบันทึกสำหรับ Car Messenger ให้ทำดังนี้
เรียกใช้สำหรับแท็กที่เกี่ยวข้อง
adb shell setprop log.tag.<TAG> DEBUG
เปิดใช้การบันทึกสำหรับ Assistant ที่โหลดไว้ล่วงหน้า
สำหรับข้อบกพร่องที่ทำซ้ำได้สูง ให้พิจารณาใช้เบรกพอยต์กับ Android Studio