Od 27 marca 2025 r. zalecamy używanie android-latest-release
zamiast aosp-main
do kompilowania i wspołtworzenia AOSP. Więcej informacji znajdziesz w artykule o zmianach w AOSP.
Tworzenie karty aplikacji
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Aby utworzyć kartę aplikacji, aplikacja musi utworzyć w manifeście dostawcę, który rozszerza klasę
AppCardContentProvider
. AppCardContentProvider
ukrywa szczegóły, aby ułatwić tworzenie kart aplikacji.
Deklaracja w pliku manifestu
Aby utworzyć kartę aplikacji, aplikacja musi utworzyć dostawcę w pliku manifestu, aby rozszerzyć 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
W przypadku każdego pakietu można zdefiniować tylko jednego dostawcę z tymi właściwościami:
android:exported="true"
android:enabled="true"
android:permission="@string/host_permission"
LUB
@string/host_permission
znajduje się w bibliotece AppCard i określa uprawnienia w zależności od wersji interfejsu Android API w systemie.
Używanie zasobu ciągu znaków działa tylko podczas kompilacji za pomocą Gradle. Gdy używasz Soong, określ ciąg znaków z wartością zasobu ciągu znaków zgodnie z odpowiednim kwalifikatorem zasobu.
(domyślny) android:grantUriPermissions="false"
(domyślny) android:forceUriPermissions="false"
Aby uniknąć nieoczekiwanych wyników, dostawca musi zdefiniować tylko jeden organ w android:authorities
.
Zadeklaruj filtr intencji oparty na działaniu,
com.android.car.appcard.APP_CARD_PROVIDER
Extend AppCardContentProvider
W tej sekcji opisujemy metody finalne override i protected.
Metody zastępowania
val authority: String
Użyj tej metody, aby zwrócić organ zdefiniowany we właściwości manifestu android:authorities
.
fun onCreate(): Boolean
Ta metoda musi wywoływać super.onCreate()
. Użyj tej metody, aby skonfigurować funkcję, która może spowodować opóźnienie, jeśli zostanie skonfigurowana w momencie wysłania żądania AppCard.
val appCardIds: List
Użyj tej metody, aby zwrócić listę obsługiwanych identyfikatorów AppCard. Zalecamy, aby każdy identyfikator był opisowy, ponieważ ten ciąg znaków jest używany do rejestrowania błędów.
fun onAppCardAdded(String, AppCardContext): AppCard
Ta metoda jest wywoływana, gdy karta aplikacji jest wyświetlana po raz pierwszy. Zawiera identyfikator powiązany z kartą aplikacji i AppCardContext
, które zawierają wskazówki dotyczące sposobu wyświetlania karty aplikacji.
Użyj tej metody, aby skonfigurować dowolną funkcję wymaganą przez karty aplikacji obsługiwane jako dostawca. Po wywołaniu tej funkcji karta aplikacji odpowiadająca podanemu identyfikatorowi jest uznawana za aktywną.
fun onAppCardRemoved(String)
Ta metoda jest wywoływana, gdy użytkownikowi nie są już wyświetlane żadne instancje karty aplikacji. Odpowiada ona za wszystkie działania związane z czyszczeniem. Gdy ta funkcja zostanie wywołana, karta aplikacji odpowiadająca podanemu identyfikatorowi zostanie uznana za nieaktywną.
fun onAppCardContextChanged(String, AppCardContext)
Ta metoda jest wywoływana, gdy system chce zaktualizować sposób wyświetlania karty aplikacji i wysyła zaktualizowany obiekt AppCardContext
.
Chronione metody finalne
fun sendAppCardUpdate(AppCard)
Wywołaj tę metodę, aby dodać do kolejki aktualizację aktywnej karty AppCard.
fun sendAppCardComponentUpdate(String, Component)
Wywołaj tę metodę, aby dodać do kolejki aktualizację komponentu w aktywnej karcie aplikacji. Jeśli dany komponent jest oznaczony tagiem EnforceFastUpdateRate
, aktualizacja jest wysyłana natychmiast.
Najczęstsze pytania
Gdzie są przykładowe implementacje?
Treść strony i umieszczone na niej fragmenty kodu podlegają licencjom opisanym w Licencji na treści. Java i OpenJDK są znakami towarowymi lub zastrzeżonymi znakami towarowymi należącymi do firmy Oracle lub jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-09-04 UTC.
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 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&\u003equot;\n \u003c android:\u003eenabled=\"tru\u003ce\"\n intent-filter\n action android:\u003ename=\"co\u003cm.android.car.\u003ea\u003cppcard.AP\u003eP_CARD_PROVIDER\" /\n /intent-filter\n /provider\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/)"]]