CarAppExtender | API reference | Android Developers (original) (raw)
Stay organized with collections Save and categorize content based on your preferences.
public final class CarAppExtender implements NotificationCompat.Extender
Helper class to add car app extensions to notifications.
By default, notifications in a car screen have the properties provided by [NotificationCompat.Builder](/reference/androidx/core/app/NotificationCompat.Builder)
. This helper class provides methods to override those properties for the car screen. However, notifications only show up in the car screen if it is extended with [CarAppExtender](/reference/androidx/car/app/notification/CarAppExtender)
, even if the extender does not override any properties. To create a notification with car extensions:
- Create a
[NotificationCompat.Builder](/reference/androidx/core/app/NotificationCompat.Builder)
, setting any desired properties. - Create a
[CarAppExtender.Builder](/reference/androidx/car/app/notification/CarAppExtender.Builder)
. - Set car-specific properties using the
set
methods of . - Create a
[CarAppExtender](/reference/androidx/car/app/notification/CarAppExtender)
by calling[build](/reference/androidx/car/app/notification/CarAppExtender.Builder#build%28%29)
. - Call
[extend](/reference/androidx/core/app/NotificationCompat.Builder#extend%28androidx.core.app.NotificationCompat.Extender%29)
to apply the extensions to a notification. - Post the notification to the notification system with the
CarNotificationManager.notify(...)
methods. Do not use theNotificationManager.notify(...)
, nor the NotificationManagerCompat.notify(...)} methods.
Notification notification = new NotificationCompat.Builder(context) ... .extend(new CarAppExtender.Builder() .set*(...) .build()) .build();
Car extensions can be accessed on an existing notification by using the CarAppExtender(Notification)
constructor, and then using the get
methods to access values.
The car screen UI is affected by the notification channel importance (Android O and above) or notification priority (below Android O) in the following ways:
- A heads-up-notification (HUN) will show if the importance is set to
[IMPORTANCE_HIGH](/reference/androidx/core/app/NotificationManagerCompat#IMPORTANCE%5FHIGH%28%29)
, or the priority is set to[PRIORITY_HIGH](/reference/androidx/core/app/NotificationCompat#PRIORITY%5FHIGH%28%29)
or above. - The notification center icon, which opens a screen with all posted notifications when tapped, will show a badge for a new notification if the importance is set to
[IMPORTANCE_DEFAULT](/reference/androidx/core/app/NotificationManagerCompat#IMPORTANCE%5FDEFAULT%28%29)
or above, or the priority is set to[PRIORITY_DEFAULT](/reference/androidx/core/app/NotificationCompat#PRIORITY%5FDEFAULT%28%29)
or above. - The notification entry will show in the notification center for all priority levels.
Calling [setImportance](/reference/androidx/car/app/notification/CarAppExtender.Builder#setImportance%28int%29)
will override the importance for the notification in the car screen.
Calling NotificationCompat.Builder#setOnlyAlertOnce(true)
will alert a high-priority notification only once in the HUN. Updating the same notification will not trigger another HUN event.
Navigation
For a navigation app's turn-by-turn (TBT) notifications, which update the same notification frequently with navigation information, the notification UI has a slightly different behavior. The app can post a TBT notification by calling NotificationCompat.Builder#setOngoing(true)
and NotificationCompat.Builder#setCategory(NotificationCompat.CATEGORY_NAVIGATION)
.
TBT notifications behave the same as regular notifications with the following exceptions:
- The notification will not be displayed if the navigation app is not the currently active navigation app, or if the app is already displaying routing information in the navigation template.
- The heads-up-notification (HUN) can be customized with a background color through
[setColor](/reference/androidx/car/app/notification/CarAppExtender.Builder#setColor%28androidx.car.app.model.CarColor%29)
. - The notification will not be displayed in the notification center.
In addition to that, the information in the navigation notification will be displayed in the rail widget at the bottom of the screen when the app is in the background.
Note that frequent HUNs distract the driver. The recommended practice is to update the TBT notification regularly on distance changes, which updates the rail widget, but call NotificationCompat.Builder#setOnlyAlertOnce(true)
unless there is a significant navigation turn event.
Summary
Public constructors
Public methods
getColor
public @Nullable CarColor getColor()
Returns the background color of the notification or null
if a default color is to be used.
getImportance
public int getImportance()
Returns the importance of the notification in the car screen.
getLargeIcon
public @Nullable Bitmap getLargeIcon()
Returns the large icon bitmap to display in the notification or null
if not set.