החל מ-27 במרץ 2025, מומלץ להשתמש ב-android-latest-release
במקום ב-aosp-main
כדי ליצור תרומות ל-AOSP. מידע נוסף זמין במאמר שינויים ב-AOSP.
יצירת כרטיס אפליקציה
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
כדי ליצור AppCard, האפליקציה צריכה ליצור ספק במניפסט שמרחיב את
AppCardContentProvider
. ה-AppCardContentProvider
מסתיר את הפרטים הבסיסיים כדי להקל על יצירת כרטיסי אפליקציה.
הצהרה במניפסט
כדי ליצור AppCard, האפליקציה צריכה ליצור ספק במניפסט כדי להרחיב את
AppCardContentProvider
.
<provider android:name=".SimpleAppCardContentProvider"
android:authorities="com.example.appcard.sample.media"
android:permission="@string/host_permission"
android:exported="true&>quot;
< android:>enabled="tru<e"
intent-filter
action android:>name="co<m.android.car.>a<ppcard.AP>P
_CARD_PROVIDER" /
/intent-filter
/provider
אפשר להגדיר רק ספק אחד לכל חבילה, עם המאפיינים הבאים:
android:exported="true"
android:enabled="true"
android:permission="@string/host_permission"
או
@string/host_permission
קיים בספריית AppCard ומגדיר הרשאה בהתאם לגרסת Android API של המערכת.
השימוש במשאב המחרוזת פועל רק כשמבצעים build באמצעות Gradle. כשמשתמשים ב-Soong, צריך לציין את המחרוזת המפורשת עם ערך משאב המחרוזת בהתאם למסווג המשאבים המתאים.
(ברירת מחדל) android:grantUriPermissions="false"
(ברירת מחדל) android:forceUriPermissions="false"
כדי להימנע מתוצאות לא צפויות, הספק צריך להגדיר רשות אחת בלבד ב-android:authorities
.
מצהירים על מסנן Intent מבוסס-פעולה,
com.android.car.appcard.APP_CARD_PROVIDER
Extend AppCardContentProvider
בקטע הזה מתוארות שיטות סופיות של override ושל protected.
שיטות לביטול
val authority: String
משתמשים בשיטה הזו כדי להחזיר את הסמכות שהוגדרה במאפיין המניפסט android:authorities
.
fun onCreate(): Boolean
This method must call super.onCreate()
. אפשר להשתמש בשיטה הזו כדי להגדיר פונקציונליות שעלולה לגרום לעיכוב אם היא מוגדרת כשמתבצעת בקשה ל-AppCard.
val appCardIds: List
אפשר להשתמש בשיטה הזו כדי להחזיר את רשימת מזהי כרטיסי האפליקציה הנתמכים. מומלץ להשתמש במזהה מפורט, כי המחרוזת הזו משמשת לרישום שגיאות ביומן.
fun onAppCardAdded(String, AppCardContext): AppCard
המערכת קוראת לשיטה הזו כשכרטיס האפליקציה מוצג בפעם הראשונה, והיא מספקת את המזהה שקשור לכרטיס האפליקציה ואת AppCardContext
שמספקים רמזים לגבי אופן ההצגה של כרטיס האפליקציה.
משתמשים בשיטה הזו כדי להגדיר כל פונקציונליות שנדרשת על ידי AppCards
שנתמכות כספק. אחרי שמפעילים את הפונקציה הזו, כרטיס האפליקציה שמתאים למזהה שצוין נחשב פעיל.
fun onAppCardRemoved(String)
המערכת קוראת לשיטה הזו כשלא מוצגים למשתמש מקרים נוספים של AppCard, והיא מטפלת בכל הניקוי. כשקוראים לפונקציה הזו, כרטיס האפליקציה
שמתאים למזהה שצוין נחשב לא פעיל.
fun onAppCardContextChanged(String, AppCardContext)
השיטה הזו מופעלת כשהמערכת רוצה לעדכן את אופן ההצגה של כרטיס אפליקציה ושולחת AppCardContext
מעודכן.
שיטות סופיות מוגנות
fun sendAppCardUpdate(AppCard)
מפעילים את השיטה הזו כדי להוסיף עדכון לתור של כרטיס אפליקציה פעיל.
fun sendAppCardComponentUpdate(String, Component)
מפעילים את השיטה הזו כדי להוסיף לעדכון רכיב בתצוגה פעילה של כרטיס אפליקציה. אם הרכיב שצוין מתויג בתג EnforceFastUpdateRate
, העדכון נשלח באופן מיידי.
שאלות נפוצות
איפה נמצאות ההטמעות לדוגמה?
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-09-04 (שעון 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-04 (שעון 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/)"]]