2025 年 3 月 27 日より、AOSP のビルドとコントリビューションには aosp-main
ではなく android-latest-release
を使用することをおすすめします。詳細については、AOSP の変更をご覧ください。
AppCard を作成する
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
AppCard を作成するには、アプリは AppCardContentProvider
を拡張するプロバイダをマニフェストで作成する必要があります。AppCardContentProvider
は、基盤となる詳細を抽象化して、AppCard の作成を容易にします。
マニフェストの宣言
AppCard を作成するには、アプリがマニフェストでプロバイダを作成して 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>
パッケージごとに 1 つのプロバイダのみを定義できます。プロバイダは次のプロパティを持ちます。
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
で 1 つの権限をのみ定義する必要があります。
アクションベースのインテント フィルタ com.android.car.appcard.APP_CARD_PROVIDER
を宣言する
AppCardContentProvider を拡張する
このセクションでは、オーバーライドと保護された final メソッドについて説明します。
メソッドをオーバーライド
val authority: String
このメソッドを使用して、android:authorities
マニフェスト プロパティで定義された権限を返します。
fun onCreate(): Boolean
このメソッドは super.onCreate()
を呼び出す必要があります。このメソッドを使用して、AppCard がリクエストされたときに設定すると遅延を引き起こす可能性のある機能を設定します。
val appCardIds: List
このメソッドを使用して、サポートされている AppCard ID のリストを返します。この文字列はエラーのロギングに使用されるため、各 ID を詳細にすることをおすすめします。
fun onAppCardAdded(String, AppCardContext): AppCard
このメソッドは、AppCard が初めて表示されたときに呼び出され、AppCard に関連する ID と、AppCard の表示方法に関するヒントを提供する AppCardContext
を返します。
このメソッドを使用して、プロバイダとしてサポートされている AppCards で必要な機能を設定します。この関数が呼び出されると、指定された ID に対応する AppCard はアクティブと見なされます。
fun onAppCardRemoved(String)
このメソッドは、ユーザーに表示される AppCard の残りのインスタンスがない場合に呼び出され、すべてのクリーンアップを処理します。この関数が呼び出されると、指定された ID に対応する AppCard は非アクティブと見なされます。
fun onAppCardContextChanged(String, AppCardContext)
このメソッドは、システムが AppCard の表示方法を更新し、更新された AppCardContext
を送信するときに呼び出されます。
保護された final メソッド
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/)"]]