如要建立 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>
每個套件只能定義一個供應商,且必須具備下列屬性:
android:exported="true"
android:enabled="true"
android:permission="@string/host_permission"
或
android:readPermission="@string/host_permission"
此外還有
android:writePermission="@string/host_permission"
@string/host_permission
存在於 AppCard 程式庫中,並根據系統的 Android API 版本定義權限。只有使用 Gradle 建構時,才能使用字串資源。使用 Soong 時,請根據適當的資源限定符,以字串資源值指定明確的字串。
(預設)
android:grantUriPermissions="false"
(預設)
android:forceUriPermissions="false"
為避免出現非預期的結果,供應商必須在
android:authorities
中只定義單一授權。宣告以動作為依據的意圖篩選器:
com.android.car.appcard.APP_CARD_PROVIDER
擴充 AppCardContentProvider
本節說明 override 和 protected 最終方法。
覆寫方法
val authority: String
android:authorities
資訊清單屬性中定義的授權。fun onCreate(): Boolean
super.onCreate()
。使用這個方法設定功能時,如果是在要求 AppCard 時設定,可能會導致延遲。val appCardIds: List
fun onAppCardAdded(String, AppCardContext): AppCard
AppCardContext
,藉此提供 AppCard 顯示方式的提示。
使用這個方法,設定 AppCards 支援的任何功能 (以供應商身分)。呼叫此函式後,系統會將與指定 ID 相對應的 AppCard 視為「有效」。
fun onAppCardRemoved(String)
fun onAppCardContextChanged(String, AppCardContext)
AppCardContext
。受保護的最終方法
fun sendAppCardUpdate(AppCard)
fun sendAppCardComponentUpdate(String, Component)
EnforceFastUpdateRate
,系統會立即傳送更新。常見問題
範例實作位置