Use AppCardHost to communicate with apps that show AppCards.
Permissions
Any app that uses an AppCardHost must have the following permissions:
android.permission.INTERACT_ACROSS_USERS_FULLandroid.permission.QUERY_ALL_PACKAGES- (In API level 34 and higher only)
android.car.permission.BIND_APP_CARD_PROVIDER
Initialize
To initialize the host, provide:
- Context
updateRateAppCard update rate in milliseconds.fastUpdateRateUpdate rate in milliseconds for components tagged withEnforceFastUpdateRateresponseExecutorA thread on which you want to receive responses from AppCard apps.
Design
An AppCardHost can be interacted with in one of two ways:
- Register as an
AppCardListener
OR,
- Interact with the
AppCardHostAPIs
AppCardListener
The AppCardListener component registers itself with an AppCardHost
to receive communication updates from the AppCardHost and AppCard apps.
The interface functions of an AppCardListener are detailed here.
fun onAppCardReceived(AppCardContainer)AppCardContainer which provides an AppCard and an
appIdentifier to identify the app that sent the AppCardfun onComponentReceived(AppCardComponentContainer)AppCardComponentContainer, which provides
an AppCards component, Identifier to identify the app that sent the
AppCard, and a string ID to point to the AppCard to which the component
is related.fun onProviderRemoved(String, String?)If authority is {@code null}, then an entire package was removed.
fun onProviderAdded(String, String?)Sample usage. Use this function as a trigger to refresh all available
AppCards in an AppCard picker. If authority is {@code null}, then an entire
package was added.
fun onPackageCommunicationError(appIdentifier, Throwable)AppCardHost encounters an error when
communicating with an AppCard provider.
Sample usage. Use this method to show to the user that an AppCard they have selected has encountered an error.
APIs
fun refreshCompatibleapp()fun destroy()fun registerListener(AppCardListener)AppCardListener.fun unregisterListener(AppCardListener)AppCardListener.fun getAllAppCards(AppCardContext)AppCardListener with all
the AppCards provided in the system with a given AppCardContext that
provides hints to the providers on how to structure their AppCard.fun requestAppCard(AppCardContext, appIdentifier, String)AppCardListener with a
specific AppCard, given an AppCardContext that gives hints to the providers
on how to structure their AppCard.fun notifyAppCardRemoved(appIdentifier, String)fun notifyAppCardInteraction(appIdentifier, String, String, String)AppCardMessageConstants.InteractionMessageConstants.MSG_INTERACTION_ON_CLICK.
onClick listener
that calls this function with appIdentifier, AppCard ID, component
ID, and interaction ID.fun sendAppCardContextUpdate(AppCardContext, appIdentifier, String)AppCardContext update for a specific AppCard. For example, when
shifting from Park mode to Drive mode, use this method to send an
AppCardContext update in which isInteractable is set to false for each
active AppCard.FAQ
Where can I find sample implementations?
Sample host. Shows all available AppCards in the system, along with testing capabilities.
DriverUI and Pano manager. Pano manager acts as the picker while DriverUI acts as the presenter.
How many AppCards can each
AppCardContentProvidersupport?An
AppCardContentProvidercan support an infinite number of AppCards. However, be sure to balance the number of AppCards with degraded performance versus a positive user experience.