ตั้งแต่วันที่ 27 มีนาคม 2025 เป็นต้นไป เราขอแนะนำให้ใช้ android-latest-release
แทน aosp-main
เพื่อสร้างและมีส่วนร่วมใน AOSP โปรดดูข้อมูลเพิ่มเติมที่หัวข้อการเปลี่ยนแปลงใน AOSP
สร้าง AppCard
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
หากต้องการสร้าง AppCard แอปต้องสร้างผู้ให้บริการในไฟล์ Manifest ที่ขยาย AppCardContentProvider
AppCardContentProvider
จะซ่อนรายละเอียดพื้นฐาน
เพื่ออำนวยความสะดวกในการสร้าง AppCard
การประกาศไฟล์ Manifest
หากต้องการสร้าง AppCard แอปต้องสร้างผู้ให้บริการในไฟล์ Manifest เพื่อขยาย
AppCardContentProvider
<provider android:name=".SimpleAppCardContentProvider"
android:authorities="com.example.appcard.sample.media"
android:permission="@string/host_permission"
android:exported="true"
android:enabled="true">
<intent-filter>
<action android:name="com.android.car.appcard.APP_CARD_PROVIDER" />
</intent-filter>
</provider>
กำหนดผู้ให้บริการได้เพียงรายเดียวต่อแพ็กเกจและมีพร็อพเพอร์ตี้ต่อไปนี้
android:exported="true"
android:enabled="true"
android:permission="@string/host_permission"
หรือ
@string/host_permission
อยู่ในไลบรารี AppCard และกำหนดสิทธิ์ตามเวอร์ชัน Android API ของระบบ
การใช้ทรัพยากรสตริงจะใช้ได้เมื่อสร้างด้วย Gradle เท่านั้น เมื่อใช้
Soong ให้ระบุสตริงที่ชัดเจนด้วยค่าทรัพยากรสตริงตาม
ตัวระบุทรัพยากรที่เหมาะสม
(ค่าเริ่มต้น) android:grantUriPermissions="false"
(ค่าเริ่มต้น) android:forceUriPermissions="false"
ผู้ให้บริการต้องกำหนดสิทธิ์เพียงรายการเดียวเท่านั้นใน android:authorities
เพื่อหลีกเลี่ยงผลลัพธ์ที่ไม่คาดคิด
ประกาศตัวกรอง Intent ที่อิงตามการดำเนินการ
com.android.car.appcard.APP_CARD_PROVIDER
ขยาย AppCardContentProvider
ส่วนนี้จะอธิบายเมธอดสุดท้ายของ override และ protected
วิธีการลบล้าง
val authority: String
ใช้วิธีนี้เพื่อแสดงผลการให้สิทธิ์ที่กำหนดไว้ในพร็อพเพอร์ตี้ไฟล์ Manifest ของ
android:authorities
fun onCreate(): Boolean
เมธอดนี้ต้องเรียกใช้ super.onCreate()
ใช้วิธีนี้
เพื่อตั้งค่าฟังก์ชันการทำงานที่อาจทำให้เกิดความล่าช้าหากตั้งค่า
เมื่อมีการขอ AppCard
val appCardIds: List
ใช้วิธีนี้เพื่อแสดงรายการรหัส AppCard ที่รองรับ เราขอแนะนำให้สร้างรหัสแต่ละรายการให้มีรายละเอียด เนื่องจากระบบจะใช้สตริงนี้เพื่อบันทึกข้อผิดพลาด
fun onAppCardAdded(String, AppCardContext): AppCard
ระบบจะเรียกใช้เมธอดนี้เมื่อแสดง AppCard เป็นครั้งแรก และ
ระบุรหัสที่เกี่ยวข้องกับ AppCard และ AppCardContext
ที่ให้
คำแนะนำเกี่ยวกับวิธีแสดง AppCard
ใช้วิธีนี้เพื่อตั้งค่าฟังก์ชันการทำงานที่ AppCards
กำหนดให้ในฐานะผู้ให้บริการ เมื่อเรียกใช้ฟังก์ชันนี้ ระบบจะถือว่า AppCard ที่
สอดคล้องกับรหัสที่ระบุใช้งานอยู่
fun onAppCardRemoved(String)
ระบบจะเรียกใช้เมธอดนี้เมื่อไม่มีอินสแตนซ์ที่เหลือของ AppCard แสดงต่อผู้ใช้ และจัดการการล้างข้อมูลทั้งหมด เมื่อเรียกใช้ฟังก์ชันนี้ ระบบจะถือว่า AppCard
ที่สอดคล้องกับรหัสที่ระบุไม่ได้ใช้งาน
fun onAppCardContextChanged(String, AppCardContext)
ระบบจะเรียกใช้เมธอดนี้เมื่อต้องการอัปเดตวิธีแสดง AppCard
และส่ง AppCardContext
ที่อัปเดตแล้ว
วิธีการสุดท้ายที่ได้รับการปกป้อง
fun sendAppCardUpdate(AppCard)
เรียกใช้เมธอดนี้เพื่อจัดคิวการอัปเดตสำหรับ AppCard ที่ใช้งานอยู่
fun sendAppCardComponentUpdate(String, Component)
เรียกใช้เมธอดนี้เพื่อจัดคิวการอัปเดตคอมโพเนนต์ใน AppCard ที่ใช้งานอยู่
หากคอมโพเนนต์ที่ระบุมีแท็ก EnforceFastUpdateRate
ระบบจะส่งการอัปเดตทันที
คำถามที่พบบ่อย
ตัวอย่างการใช้งานอยู่ที่ไหน
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-09-05 UTC
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2025-09-05 UTC"],[],[],null,["To create an AppCard, an app must create a provider in the manifest that extends\n`AppCardContentProvider`. The `AppCardContentProvider` abstracts away underlying\ndetails to facilitate the creation of AppCards.\n\nManifest declaration\n\nTo create an AppCard, an app must create a provider in the manifest to extend\n`AppCardContentProvider`. \n\n \u003cprovider android:name=\".SimpleAppCardContentProvider\"\n android:authorities=\"com.example.appcard.sample.media\"\n android:permission=\"@string/host_permission\"\n android:exported=\"true\"\n android:enabled=\"true\"\u003e\n \u003cintent-filter\u003e\n \u003caction android:name=\"com.android.car.appcard.APP_CARD_PROVIDER\" /\u003e\n \u003c/intent-filter\u003e\n \u003c/provider\u003e\n\n**Only one provider can be defined per package** and with these properties:\n\n- `android:exported=\"true\"`\n- `android:enabled=\"true\"`\n- `android:permission=\"@string/host_permission\"`\n\n OR,\n - `android:readPermission=\"@string/host_permission\"`\n\n AND,\n\n `android:writePermission=\"@string/host_permission\"`\n- `@string/host_permission` exists in the AppCard library and defines a\n permission depending on the Android API version of the system.\n\n Using the string resource works only when building with Gradle. When using\n Soong, specify the explicit string with the string resource value according\n to the appropriate resource qualifier.\n- (*default* ) `android:grantUriPermissions=\"false\"`\n\n- (*default* ) `android:forceUriPermissions=\"false\"`\n\n To avoid unexpected results, it's required that the provider define a single\n authority **only** in `android:authorities`.\n- Declare an action-based intent filter,\n `com.android.car.appcard.APP_CARD_PROVIDER`\n\nExtend AppCardContentProvider\n\nThis section describes **override** and **protected** final methods.\n\nOverride methods\n\n\u003cbr /\u003e\n\n`val authority: String` Use this method to return the authority defined in the `android:authorities` manifest property.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n`fun onCreate(): Boolean` This method must call `super.onCreate()`. Use this method to set up functionality that could potentially cause a delay if set up when an AppCard is requested.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n`val appCardIds: List` Use this method to return the list of supported AppCard IDs. We recommend making each ID verbose since this string is used to log errors.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n`fun onAppCardAdded(String, AppCardContext): AppCard` This method is called when an AppCard is shown for the first time and provides the ID related to the AppCard and the `AppCardContext` that provide hints as to how the AppCard is displayed.\n\n\u003cbr /\u003e\n\nUse this method to set up any functionality required by the AppCards\nsupported as a provider. Once this function is called, the AppCard that\ncorresponds to the given ID is considered to be **active.**\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n`fun onAppCardRemoved(String)` This method is called when no remaining instances of the AppCard are shown to the user and handles all clean up. When this function is called, the AppCard that corresponds to the given ID is considered **inactive.**\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n`fun onAppCardContextChanged(String, AppCardContext)` This method is called when the system wants to update how an AppCard is displayed and sends an updated `AppCardContext`.\n\n\u003cbr /\u003e\n\nProtected final methods\n\n\u003cbr /\u003e\n\n`fun sendAppCardUpdate(AppCard)` Invoke this method to queue an update for an active AppCard.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n`fun sendAppCardComponentUpdate(String, Component)` Invoke this method to queue an update for a component in an active AppCard. If the given component is tagged with `EnforceFastUpdateRate`, then the update is sent immediately.\n\n\u003cbr /\u003e\n\nFAQ\n\nWhere are the sample implementations?\n\n- [Calendar AppCard](https://android.googlesource.com/platform/packages/apps/Car/libs/+/refs/tags/ub-automotive-master-20250418/car-app-card-lib/sample-calendar-app/)\n- [Media AppCard](https://android.googlesource.com/platform/packages/apps/Car/libs/+/refs/tags/ub-automotive-master-20250418/car-app-card-lib/sample-media-app/)\n- [Weather AppCard](https://android.googlesource.com/platform/packages/apps/Car/libs/+/refs/tags/ub-automotive-master-20250418/car-app-card-lib/sample-weather-app/)"]]