วงจรการใช้งานบริการเบราว์เซอร์สื่อ
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ส่วนนี้อธิบายวิธีที่ Android Automotive OS (AAOS) และ Android Auto
โต้ตอบกับบริการเบราว์เซอร์สื่อในเวิร์กโฟลว์ของผู้ใช้ทั่วไป
ผู้ใช้เปิดแอปของคุณใน AAOS หรือ Android Auto
แอปโฮสต์จะเชื่อมโยงกับบริการเบราว์เซอร์สื่อ ซึ่งระบบปฏิบัติการจะเริ่มทำงานหากยังไม่ได้ทำงาน ในการติดตั้งใช้งานเมธอด onCreate()
คุณต้องสร้างและลงทะเบียนออบเจ็กต์ MediaSessionCompat
และออบเจ็กต์
การเรียกกลับ ดูข้อมูลเพิ่มเติมได้ที่ลงทะเบียนเซสชันสื่อ
AAOS หรือ Android Auto จะเรียกใช้เมธอด onGetRoot
ของบริการเพื่อ
ดึงข้อมูลรูทในลำดับชั้นของเนื้อหา ระบบจะไม่แสดงรูท
แต่จะดึงเนื้อหาเพิ่มเติมจากแอปในขั้นตอนต่อๆ ไปแทน
AAOS หรือ Android Auto จะเรียกใช้เมธอด onLoadChildren()
ของบริการเพื่อ
ดึงข้อมูลรายการสื่อย่อยของรายการสื่อรูท AAOS และ Android Auto
จะแสดงรายการสื่อเหล่านี้เป็นรายการเนื้อหาระดับบนสุด ดูข้อมูลเพิ่มเติมเกี่ยวกับสิ่งที่ระบบคาดหวังได้ที่หัวข้อ
จัดโครงสร้างเมนูรูท
เมื่อผู้ใช้เลือกรายการสื่อที่เรียกดูได้ ระบบจะเรียกใช้เมธอด onLoadChildren()
ของบริการอีกครั้ง
หากผู้ใช้เลือกรายการสื่อที่เล่นได้ AAOS หรือ Android Auto จะเรียกใช้
เมธอดการเรียกกลับของเซสชันสื่อที่เหมาะสมเพื่อดำเนินการ
หากแอปของคุณรองรับ ผู้ใช้จะค้นหาเนื้อหาของคุณได้ด้วย ในกรณีนี้ AAOS หรือ Android Auto จะเรียกใช้เมธอด onSearch()
ของบริการ
ดูข้อมูลเพิ่มเติมได้ที่แสดงผลการค้นหาที่เรียกดูได้
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-22 UTC
[null,null,["อัปเดตล่าสุด 2025-08-22 UTC"],[],[],null,["# Media browser service lifecycle\n\nThis section describes how Android Automotive OS (AAOS) and Android Auto\ninteract with your media browser service during a typical user workflow:\n\n1. The user launches your app on AAOS or Android Auto.\n\n2. The host app binds to your media browser service, which the OS starts if it\n isn't already running. In your implementation of the `onCreate()` method,\n you must create and register a [`MediaSessionCompat`](/reference/android/support/v4/media/session/MediaSessionCompat) object and its\n callback object. To learn more, see [Register a media session](/training/cars/media/enable-playback#registering_mediasession).\n\n3. AAOS or Android Auto calls your service's [`onGetRoot`](/training/cars/media/content-hierarchy#onGetRoot) method to\n retrieve the root in your content hierarchy. The root is not displayed.\n Instead, it retrieves more content from your app in subsequent steps.\n\n4. AAOS or Android Auto calls your service's [`onLoadChildren()`](/reference/androidx/media/MediaBrowserServiceCompat#onLoadChildren(java.lang.String,androidx.media.MediaBrowserServiceCompat.Result%3Cjava.util.List%3Candroid.support.v4.media.MediaBrowserCompat.MediaItem%3E%3E)%5D) method to\n retrieve the descendants of the root media item. AAOS and Android Auto\n display these media items as the top level of content items. See\n [Structure the root menu](/training/cars/media/content-media-browser/content-hierarchy#root-menu-structure) to learn more about what the system expects.\n\n5. When the user selects a **browsable** media item, your service's\n `onLoadChildren()` method is called again.\n\n6. If the user selects a **playable** media item, AAOS or Android Auto calls\n the appropriate media session callback method to perform the action.\n\n7. If supported by your app, the user can also search your content. In this\n case, AAOS or Android Auto call your service's [`onSearch()`](/reference/androidx/media/MediaBrowserServiceCompat#onSearch(java.lang.String,android.os.Bundle,androidx.media.MediaBrowserServiceCompat.Result%3Cjava.util.List%3Candroid.support.v4.media.MediaBrowserCompat.MediaItem%3E%3E)) method.\n To learn more, see [Display browsable search results](/training/cars/media/create-media-browser/browsable-search)."]]