แอปที่รองรับการรับส่งข้อความสามารถขยายการแจ้งเตือนการรับส่งข้อความเพื่อให้ Android Auto ใช้การแจ้งเตือนเหล่านั้นได้เมื่อทำงานอยู่ การแจ้งเตือนเหล่านี้จะแสดงโดย Android Auto และช่วยให้ผู้ใช้อ่านและตอบกลับข้อความในอินเทอร์เฟซที่สอดคล้องกันและมีสิ่งรบกวนน้อย และเมื่อใช้ MessagingStyle API คุณจะได้รับการแจ้งเตือนข้อความที่เพิ่มประสิทธิภาพสำหรับอุปกรณ์ Android ทั้งหมด รวมถึง Android
Auto การเพิ่มประสิทธิภาพประกอบด้วย UI ที่ออกแบบมาเป็นพิเศษสำหรับการแจ้งเตือนข้อความ
ภาพเคลื่อนไหวที่ได้รับการปรับปรุง และการรองรับรูปภาพในบรรทัด
คู่มือนี้แสดงวิธีขยายแอปที่แสดงข้อความต่อผู้ใช้และรับคำตอบของผู้ใช้ เช่น แอปแชท เพื่อส่งต่อการแสดงข้อความและการรับคำตอบไปยัง Android Auto การผสานรวมนี้จะช่วยให้ผู้ใช้ดูได้เฉพาะประวัติข้อความจากการแจ้งเตือนที่ได้รับในระหว่างเซสชัน Android Auto ที่ใช้งานอยู่ เท่านั้น หากต้องการแสดงข้อความจากก่อนที่เซสชัน Android Auto ที่ใช้งานอยู่จะเริ่มขึ้น คุณสามารถสร้างประสบการณ์การรับส่งข้อความแบบเทมเพลตได้
ดูคำแนะนำด้านการออกแบบที่เกี่ยวข้องได้ที่แอปการสื่อสารในฮับ Design for Cars
เริ่มต้นใช้งาน
หากต้องการให้บริการรับส่งข้อความสำหรับ Android Auto แอปของคุณต้องประกาศการรองรับ Android Auto ในไฟล์ Manifest และสามารถทำสิ่งต่อไปนี้ได้
- ประกาศการรองรับ Android Auto
- สร้างและส่งออบเจ็กต์
NotificationCompat.MessagingStyleที่มีออบเจ็กต์Actionตอบกลับและทำเครื่องหมายว่าอ่านแล้ว - จัดการการตอบกลับและทำเครื่องหมายการสนทนาว่าอ่านแล้วด้วย
Service
แนวคิดและออบเจ็กต์
ก่อนที่จะเริ่มออกแบบแอป คุณควรทำความเข้าใจวิธีที่ Android Auto จัดการการรับส่งข้อความ
การสื่อสารแต่ละส่วนเรียกว่าข้อความและแสดงโดย
คลาส MessagingStyle.Message ข้อความประกอบด้วยผู้ส่ง เนื้อหาข้อความ และเวลาที่ส่งข้อความ
การสื่อสารระหว่างผู้ใช้เรียกว่าการสนทนาและแสดงด้วยออบเจ็กต์
MessagingStyle การสนทนาหรือ MessagingStyle จะมีชื่อ
ข้อความ และระบุว่าการสนทนาเป็นแบบกลุ่มผู้ใช้หรือไม่
หากต้องการแจ้งให้ผู้ใช้ทราบเกี่ยวกับการอัปเดตการสนทนา เช่น ข้อความใหม่ แอปจะโพสต์
Notification ไปยังระบบ Android Notification นี้ใช้ออบเจ็กต์
MessagingStyle เพื่อแสดง UI เฉพาะการรับส่งข้อความใน
แผงการแจ้งเตือน แพลตฟอร์ม Android จะส่ง Notification นี้ไปยัง Android Auto ด้วย และระบบจะ
ดึงข้อมูล MessagingStyle ออกมาเพื่อใช้โพสต์การแจ้งเตือนบนจอแสดงผลของรถ
นอกจากนี้ Android Auto ยังกำหนดให้แอปเพิ่มออบเจ็กต์ Action ลงใน Notification
เพื่อให้ผู้ใช้ตอบกลับข้อความหรือทำเครื่องหมายว่าอ่านแล้วได้โดยตรงจากจอแสดงผลของรถยนต์
โดยสรุป การสนทนาเดียวจะแสดงด้วยออบเจ็กต์ Notification ที่
จัดรูปแบบด้วยออบเจ็กต์ MessagingStyle MessagingStyle มีข้อความทั้งหมดในการสนทนานั้นในออบเจ็กต์ MessagingStyle.Message อย่างน้อย 1 รายการ
และเพื่อให้เป็นไปตามข้อกำหนดของ Android Auto แอปต้องแนบออบเจ็กต์การตอบกลับและ
ทำเครื่องหมายว่าอ่านแล้วActionกับ Notification
โฟลว์การรับส่งข้อความ
ส่วนนี้อธิบายโฟลว์การรับส่งข้อความทั่วไประหว่างแอปของคุณกับ Android Auto
- แอปของคุณได้รับข้อความ
- แอปของคุณสร้างออบเจ็กต์การแจ้งเตือน
MessagingStyleพร้อมการตอบกลับและActionทำเครื่องหมายว่าอ่านแล้ว - Android Auto จะได้รับเหตุการณ์ "การแจ้งเตือนใหม่" จากระบบ Android
และค้นหา
MessagingStyle, ตอบกลับActionและทำเครื่องหมายว่าอ่านแล้วAction - Android Auto จะสร้างและแสดงการแจ้งเตือนในรถ
- หากผู้ใช้แตะการแจ้งเตือนบนจอแสดงผลของรถ Android Auto จะทริกเกอร์การทำเครื่องหมายว่าอ่านแล้ว
Action- ในเบื้องหลัง แอปของคุณต้องจัดการเหตุการณ์ทำเครื่องหมายว่าอ่านแล้วนี้
- หากผู้ใช้ตอบกลับการแจ้งเตือนโดยใช้เสียง Android Auto จะใส่
ข้อความถอดเสียงคำตอบของผู้ใช้ลงในคำตอบ
Actionแล้ว ทริกเกอร์- แอปของคุณต้องจัดการเหตุการณ์การตอบกลับนี้ในเบื้องหลัง
สมมติฐานเบื้องต้น
หน้านี้ไม่ได้แนะนำวิธีสร้างแอปรับส่งข้อความทั้งหมด ตัวอย่างโค้ดต่อไปนี้มีบางอย่างที่แอปของคุณต้องมีก่อนที่จะเริ่มรองรับการรับส่งข้อความด้วย Android Auto
data class YourAppConversation(
val id: Int,
val title: String,
val recipients: MutableList<YourAppUser>,
val icon: Bitmap) {
companion object {
/** Fetches [YourAppConversation] by its [id]. */
fun getById(id: Int): YourAppConversation = // ...
}
/** Replies to this conversation with the given [message]. */
fun reply(message: String) {}
/** Marks this conversation as read. */
fun markAsRead() {}
/** Retrieves all unread messages from this conversation. */
fun getUnreadMessages(): List<YourAppMessage> { return /* ... */ }
}
data class YourAppUser(val id: Int, val name: String, val icon: Uri)
data class YourAppMessage(
val id: Int,
val sender: YourAppUser,
val body: String,
val timeReceived: Long)
ประกาศการรองรับ Android Auto
เมื่อ Android Auto ได้รับการแจ้งเตือนจากแอปส่งข้อความ ระบบจะตรวจสอบว่า แอปได้ประกาศการรองรับ Android Auto แล้ว หากต้องการเปิดใช้การรองรับนี้ ให้รวมรายการต่อไปนี้ในไฟล์ Manifest ของแอป
<application>
...
<meta-data
android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc"/>
...
</application>
รายการในไฟล์ Manifest นี้อ้างอิงถึงไฟล์ XML อื่น automotive_app_desc.xml ที่คุณต้องสร้างในไดเรกทอรี res/xml ของโมดูลแอป ใน
automotive_app_desc.xml ให้ประกาศความสามารถของ Android Auto ที่แอปของคุณ
รองรับ หากต้องการประกาศการรองรับการแจ้งเตือน ให้ระบุข้อมูลต่อไปนี้
<automotiveApp>
<uses name="notification" />
</automotiveApp>
หากตั้งค่าแอปเป็นตัวแฮนเดิล SMS เริ่มต้นได้ ให้ตรวจสอบว่าได้รวมองค์ประกอบต่อไปนี้
<uses> หากไม่ทำเช่นนั้น Android Auto จะใช้ตัวแฮนเดิลเริ่มต้นในตัวเพื่อจัดการข้อความ SMS/MMS ขาเข้าเมื่อตั้งค่าแอปเป็นตัวแฮนเดิล SMS เริ่มต้น ซึ่งอาจทำให้มีการแจ้งเตือนซ้ำ
<automotiveApp>
...
<uses name="sms" />
</automotiveApp>
นำเข้าไลบรารีหลักของ AndroidX
การสร้างการแจ้งเตือนเพื่อใช้กับ Android Auto ต้องใช้ไลบรารีหลักของ AndroidX นำเข้าไลบรารีไปยังโปรเจ็กต์โดยทำดังนี้
- ในไฟล์
build.gradleระดับบนสุด ให้รวมทรัพยากร Dependency ในที่เก็บ Maven ของ Google ดังที่แสดงในตัวอย่างต่อไปนี้
Groovy
allprojects { repositories { google() } }
Kotlin
allprojects { repositories { google() } }
- ในไฟล์
build.gradleของโมดูลแอป ให้รวมทรัพยากร Dependency ของไลบรารี AndroidX Core ดังที่แสดงในตัวอย่างต่อไปนี้
Groovy
dependencies { // If your app is written in Java implementation 'androidx.core:core:1.17.0' // If your app is written in Kotlin implementation 'androidx.core:core-ktx:1.17.0' }
Kotlin
dependencies { // If your app is written in Java implementation("androidx.core:core:1.17.0") // If your app is written in Kotlin implementation("androidx.core:core-ktx:1.17.0") }
จัดการการดำเนินการของผู้ใช้
แอปรับส่งข้อความของคุณต้องมีวิธีจัดการการอัปเดตการสนทนาผ่านAction สำหรับ Android Auto Actionออบเจ็กต์ที่แอปของคุณต้องจัดการมี 2 ประเภท ได้แก่ ตอบกลับและทำเครื่องหมายว่าอ่านแล้ว เราขอแนะนำให้จัดการโดยใช้
IntentService ซึ่งช่วยให้จัดการการเรียกที่อาจมีค่าใช้จ่ายสูงในเบื้องหลังได้อย่างยืดหยุ่น ทำให้เธรดหลักของแอปทำงานได้
กำหนดการดำเนินการผ่าน Intent
Intent คือสตริงพื้นฐานที่คุณเลือกซึ่งระบุว่า
Intent มีไว้เพื่ออะไร เนื่องจากบริการเดียวสามารถจัดการ Intent ได้หลายประเภท
การกำหนดสตริงการดำเนินการหลายรายการจึงง่ายกว่าการกำหนดคอมโพเนนต์ IntentService หลายรายการ
แอปส่งข้อความตัวอย่างในคู่มือนี้มีการดำเนินการ 2 ประเภทที่จำเป็น ได้แก่ ตอบกลับ และทำเครื่องหมายว่าอ่านแล้ว ดังที่แสดงในตัวอย่างโค้ดต่อไปนี้
private const val ACTION_REPLY = "com.example.REPLY"
private const val ACTION_MARK_AS_READ = "com.example.MARK_AS_READ"
สร้างบริการ
หากต้องการสร้างบริการที่จัดการออบเจ็กต์ Action เหล่านี้ คุณต้องมี
รหัสการสนทนา ซึ่งเป็นโครงสร้างข้อมูลที่กำหนดโดยแอปของคุณ
เพื่อระบุการสนทนา นอกจากนี้ คุณยังต้องมีคีย์อินพุตระยะไกล ซึ่งเราจะอธิบายรายละเอียดในส่วนนี้ในภายหลัง ตัวอย่างโค้ดต่อไปนี้สร้าง
บริการเพื่อจัดการการดำเนินการที่จำเป็น
private const val EXTRA_CONVERSATION_ID_KEY = "conversation_id"
private const val REMOTE_INPUT_RESULT_KEY = "reply_input"
/**
* An [IntentService] that handles reply and mark-as-read actions for
* [YourAppConversation]s.
*/
class MessagingService : IntentService("MessagingService") {
override fun onHandleIntent(intent: Intent?) {
// Fetches internal data.
val conversationId = intent!!.getIntExtra(EXTRA_CONVERSATION_ID_KEY, -1)
// Searches the database for that conversation.
val conversation = YourAppConversation.getById(conversationId)
// Handles the action that was requested in the intent. The TODOs
// are addressed in a later section.
when (intent.action) {
ACTION_REPLY -> TODO()
ACTION_MARK_AS_READ -> TODO()
}
}
}
หากต้องการเชื่อมโยงบริการนี้กับแอป คุณต้องลงทะเบียนบริการ ในไฟล์ Manifest ของแอปด้วย ดังที่แสดงในตัวอย่างต่อไปนี้
<application>
<service android:name="com.example.MessagingService" />
...
</application>
สร้างและจัดการความตั้งใจ
แอปอื่นๆ รวมถึง Android Auto จะรับ Intent ที่ทริกเกอร์
MessagingService ไม่ได้เนื่องจากมีการส่ง Intent ไปยังแอปอื่นๆ ผ่าน
PendingIntent เนื่องจากข้อจำกัดนี้ ให้สร้างออบเจ็กต์ RemoteInput
เพื่อให้แอปอื่นๆ ระบุข้อความตอบกลับไปยังแอปของคุณได้ ดังที่แสดงในตัวอย่างต่อไปนี้
/**
* Creates a [RemoteInput] that lets remote apps provide a response string
* to the underlying [Intent] within a [PendingIntent].
*/
fun createReplyRemoteInput(context: Context): RemoteInput {
// RemoteInput.Builder accepts a single parameter: the key to use to store
// the response in.
return RemoteInput.Builder(REMOTE_INPUT_RESULT_KEY).build()
// Note that the RemoteInput has no knowledge of the conversation. This is
// because the data for the RemoteInput is bound to the reply Intent using
// static methods in the RemoteInput class.
}
/** Creates an [Intent] that handles replying to the given [appConversation]. */
fun createReplyIntent(
context: Context, appConversation: YourAppConversation): Intent {
// Creates the intent backed by the MessagingService.
val intent = Intent(context, MessagingService::class.java)
// Lets the MessagingService know this is a reply request.
intent.action = ACTION_REPLY
// Provides the ID of the conversation that the reply applies to.
intent.putExtra(EXTRA_CONVERSATION_ID_KEY, appConversation.id)
return intent
}
ในACTION_REPLY switch clause ภายใน MessagingService ให้ดึงข้อมูลที่จะใช้ในการตอบกลับ Intent ดังตัวอย่างต่อไปนี้
ACTION_REPLY -> {
// Extracts reply response from the intent using the same key that the
// RemoteInput uses.
val results: Bundle = RemoteInput.getResultsFromIntent(intent)
val message = results.getString(REMOTE_INPUT_RESULT_KEY)
// This conversation object comes from the MessagingService.
conversation.reply(message)
}
คุณจัดการฟีเจอร์ทำเครื่องหมายว่าอ่านแล้ว Intent ได้ในลักษณะเดียวกัน แต่ไม่จำเป็นต้องมี RemoteInput ดังตัวอย่างต่อไปนี้
/** Creates an [Intent] that handles marking the [appConversation] as read. */
fun createMarkAsReadIntent(
context: Context, appConversation: YourAppConversation): Intent {
val intent = Intent(context, MessagingService::class.java)
intent.action = ACTION_MARK_AS_READ
intent.putExtra(EXTRA_CONVERSATION_ID_KEY, appConversation.id)
return intent
}
ACTION_MARK_AS_READ สวิตช์คลอสภายใน MessagingService ไม่ต้องมีตรรกะเพิ่มเติม ดังที่แสดงในตัวอย่างต่อไปนี้
// Marking as read has no other logic.
ACTION_MARK_AS_READ -> conversation.markAsRead()
แจ้งเตือนผู้ใช้เกี่ยวกับข้อความ
เมื่อการจัดการการดำเนินการในการสนทนาเสร็จสมบูรณ์แล้ว ขั้นตอนถัดไปคือการสร้าง การแจ้งเตือนที่สอดคล้องกับ Android Auto
สร้างการดำเนินการ
Action สามารถส่งออบเจ็กต์ไปยังแอปอื่นๆ ได้โดยใช้ Notification เพื่อทริกเกอร์เมธอดในแอปเดิม ซึ่งเป็นวิธีที่ Android Auto ใช้เพื่อทำเครื่องหมายการสนทนาว่าอ่านแล้วหรือตอบกลับ
หากต้องการสร้าง Action ให้เริ่มด้วย Intent ตัวอย่างต่อไปนี้แสดงวิธีสร้างIntent "ตอบกลับ" โดยใช้เมธอด createReplyIntent() จากส่วนก่อนหน้า
fun createReplyAction(
context: Context, appConversation: YourAppConversation): Action {
val replyIntent: Intent = createReplyIntent(context, appConversation)
// ...
จากนั้นให้ใส่ Intent นี้ไว้ใน PendingIntent ซึ่งจะเตรียมไว้สำหรับการใช้งานแอปภายนอก
PendingIntent จะล็อกการเข้าถึง Intent ที่ห่อหุ้มทั้งหมดโดย
แสดงเฉพาะชุดเมธอดที่เลือกซึ่งช่วยให้แอปที่รับเรียกใช้ Intent หรือรับชื่อแพ็กเกจของแอปต้นทางได้ แอปภายนอกไม่สามารถ
เข้าถึง Intent หรือข้อมูลภายในได้
// ...
val replyPendingIntent = PendingIntent.getService(
context,
createReplyId(appConversation), // Method explained later.
replyIntent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE)
// ...
ก่อนตั้งค่าการตอบกลับ Action โปรดทราบว่า Android Auto มีข้อกำหนด 3 ข้อสำหรับการตอบกลับ Action ดังนี้
- ต้องตั้งค่าการดำเนินการเชิงความหมายเป็น
Action.SEMANTIC_ACTION_REPLY Actionต้องระบุว่าจะไม่แสดงอินเทอร์เฟซผู้ใช้เมื่อทริกเกอร์Actionต้องมีRemoteInputเพียงรายการเดียว
ตัวอย่างโค้ดต่อไปนี้จะตั้งค่าการตอบกลับ Action ที่เป็นไปตาม
ข้อกำหนดที่ระบุไว้ก่อนหน้านี้
// ...
val replyAction = Action.Builder(R.drawable.reply, "Reply", replyPendingIntent)
// Provides context to what firing the Action does.
.setSemanticAction(Action.SEMANTIC_ACTION_REPLY)
// The action doesn't show any UI, as required by Android Auto.
.setShowsUserInterface(false)
// Don't forget the reply RemoteInput. Android Auto will use this to
// make a system call that will add the response string into
// the reply intent so it can be extracted by the messaging app.
.addRemoteInput(createReplyRemoteInput(context))
.build()
return replyAction
}
การจัดการการดำเนินการทำเครื่องหมายว่าอ่านแล้วจะคล้ายกัน ยกเว้นว่าจะไม่มี RemoteInput
ดังนั้น Android Auto จึงมีข้อกำหนด 2 ข้อสำหรับการทำเครื่องหมายว่าอ่านแล้ว Action
- ตั้งค่าการดำเนินการเชิงความหมายเป็น
Action.SEMANTIC_ACTION_MARK_AS_READ - การดำเนินการนี้ระบุว่าจะไม่แสดงอินเทอร์เฟซผู้ใช้เมื่อมีการเรียกใช้
ตัวอย่างโค้ดต่อไปนี้จะตั้งค่าเครื่องหมายว่าอ่านแล้ว Action ที่ตรงตามข้อกำหนดเหล่านี้
fun createMarkAsReadAction(
context: Context, appConversation: YourAppConversation): Action {
val markAsReadIntent = createMarkAsReadIntent(context, appConversation)
val markAsReadPendingIntent = PendingIntent.getService(
context,
createMarkAsReadId(appConversation), // Method explained later.
markAsReadIntent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
val markAsReadAction = Action.Builder(
R.drawable.mark_as_read, "Mark as Read", markAsReadPendingIntent)
.setSemanticAction(Action.SEMANTIC_ACTION_MARK_AS_READ)
.setShowsUserInterface(false)
.build()
return markAsReadAction
}
เมื่อสร้าง PendingIntent คุณจะใช้วิธีการ 2 วิธี ได้แก่ createReplyId() และ createMarkAsReadId() วิธีการเหล่านี้ทำหน้าที่เป็นรหัสคำขอสำหรับแต่ละ
PendingIntent ซึ่ง Android ใช้เพื่อควบคุม PendingIntent ที่มีอยู่
เมธอด create() ต้องแสดงรหัสที่ไม่ซ้ำกันสำหรับแต่ละการสนทนา แต่
การเรียกซ้ำสำหรับการสนทนาเดียวกันต้องแสดงรหัสที่ไม่ซ้ำกันที่สร้างขึ้นแล้ว
ลองพิจารณาตัวอย่างที่มีการสนทนา 2 รายการ ได้แก่ A และ B โดยการสนทนา A มีรหัสการตอบกลับ
เป็น 100 และรหัสการทำเครื่องหมายว่าอ่านแล้วเป็น 101 รหัสการตอบกลับของการสนทนา B คือ 102 และ
รหัสการทำเครื่องหมายว่าอ่านแล้วคือ 103 หากมีการอัปเดตการสนทนา A รหัสการตอบกลับและรหัสทำเครื่องหมายว่าอ่านแล้วจะยังคงเป็น 100 และ 101 ดูข้อมูลเพิ่มเติมได้ที่
PendingIntent.FLAG_UPDATE_CURRENT
สร้าง MessagingStyle
MessagingStyle เป็นผู้ให้บริการข้อมูลการรับส่งข้อความและเป็นสิ่งที่ Android
Auto ใช้เพื่ออ่านออกเสียงแต่ละข้อความในการสนทนา
ก่อนอื่นคุณต้องระบุผู้ใช้อุปกรณ์เป็นออบเจ็กต์ Person ดังตัวอย่างต่อไปนี้
fun createMessagingStyle(
context: Context, appConversation: YourAppConversation): MessagingStyle {
// Method defined by the messaging app.
val appDeviceUser: YourAppUser = getAppDeviceUser()
val devicePerson = Person.Builder()
// The display name (also the name that's read aloud in Android auto).
.setName(appDeviceUser.name)
// The icon to show in the notification shade in the system UI (outside
// of Android Auto).
.setIcon(appDeviceUser.icon)
// A unique key in case there are multiple people in this conversation with
// the same name.
.setKey(appDeviceUser.id)
.build()
// ...
จากนั้นคุณจะสร้างออบเจ็กต์ MessagingStyle และระบุรายละเอียดบางอย่าง
เกี่ยวกับการสนทนาได้
// ...
val messagingStyle = MessagingStyle(devicePerson)
// Sets the conversation title. If the app's target version is lower
// than P, this will automatically mark the conversation as a group (to
// maintain backward compatibility). Use `setGroupConversation` after
// setting the conversation title to explicitly override this behavior. See
// the documentation for more information.
messagingStyle.setConversationTitle(appConversation.title)
// Group conversation means there is more than 1 recipient, so set it as such.
messagingStyle.setGroupConversation(appConversation.recipients.size > 1)
// ...
สุดท้าย ให้เพิ่มข้อความที่ยังไม่ได้อ่าน
// ...
for (appMessage in appConversation.getUnreadMessages()) {
// The sender is also represented using a Person object.
val senderPerson = Person.Builder()
.setName(appMessage.sender.name)
.setIcon(appMessage.sender.icon)
.setKey(appMessage.sender.id)
.build()
// Adds the message. More complex messages, like images,
// can be created and added by instantiating the MessagingStyle.Message
// class directly. See documentation for details.
messagingStyle.addMessage(
appMessage.body, appMessage.timeReceived, senderPerson)
}
return messagingStyle
}
แพ็กเกจและส่งการแจ้งเตือน
หลังจากสร้างออบเจ็กต์ Action และ MessagingStyle แล้ว คุณจะสร้าง
และโพสต์ Notification ได้
fun notify(context: Context, appConversation: YourAppConversation) {
// Creates the actions and MessagingStyle.
val replyAction = createReplyAction(context, appConversation)
val markAsReadAction = createMarkAsReadAction(context, appConversation)
val messagingStyle = createMessagingStyle(context, appConversation)
// Creates the notification.
val notification = NotificationCompat.Builder(context, channel)
// A required field for the Android UI.
.setSmallIcon(R.drawable.notification_icon)
// Shows in Android Auto as the conversation image.
.setLargeIcon(appConversation.icon)
// Adds MessagingStyle.
.setStyle(messagingStyle)
// Adds reply action.
.addAction(replyAction)
// Makes the mark-as-read action invisible, so it doesn't appear
// in the Android UI but the app satisfies Android Auto's
// mark-as-read Action requirement. Both required actions can be made
// visible or invisible; it is a stylistic choice.
.addInvisibleAction(markAsReadAction)
.build()
// Posts the notification for the user to see.
val notificationManagerCompat = NotificationManagerCompat.from(context)
notificationManagerCompat.notify(appConversation.id, notification)
}
แหล่งข้อมูลเพิ่มเติม
รายงานปัญหาเกี่ยวกับการแจ้งเตือนการรับส่งข้อความของ Android Auto
หากพบปัญหาขณะพัฒนาการแจ้งเตือนการรับส่งข้อความสำหรับ Android Auto คุณสามารถรายงานปัญหาได้โดยใช้ Google Issue Tracker โปรด กรอกข้อมูลที่ขอทั้งหมดในเทมเพลตปัญหา
ก่อนยื่นปัญหาใหม่ โปรดตรวจสอบว่ามีการรายงานปัญหาดังกล่าวในรายการปัญหาแล้วหรือไม่ คุณติดตามและโหวตปัญหาได้โดยคลิกดาวสำหรับปัญหาในเครื่องมือติดตาม ดูข้อมูลเพิ่มเติมได้ที่การติดตามปัญหา