CarAppExtender
public
class
CarAppExtender
extends Object
implements
NotificationCompat.Extender
java.lang.Object | |
↳ | com.google.android.libraries.car.app.notification.CarAppExtender |
Helper class to add car app extensions to notifications.
By default, notifications in a car screen have the properties provided by 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
, even if the extender does not override any
properties. To create a notification with car extensions:
- Create a
NotificationCompat.Builder
, setting any desired properties. - Create a
CarAppExtender.Builder
withbuilder()
. - Set car-specific properties using the
set
methods ofCarAppExtender.Builder
. - Create a
CarAppExtender
by callingCarAppExtender.Builder.build()
. - Call
NotificationCompat.Builder.extend(NotificationCompat.Extender)
to apply the extensions to a notification. - Post the notification to the notification system with the
NotificationManagerCompat.notify(...)
methods and not theNotificationManager.notify(...)
methods.
Notification notification = new NotificationCompat.Builder(context) ... .extend(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
NotificationManagerCompat.IMPORTANCE_HIGH
, or the priority is set toNotificationCompat.PRIORITY_HIGH
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
NotificationManagerCompat.IMPORTANCE_DEFAULT
or above, or the priority is set toNotificationCompat.PRIORITY_DEFAULT
or above. - The notification entry will show in the notification center for all priority levels.
CarAppExtender.Builder.setImportance(int)
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)
. The car screen
UI is affected in the following ways:
- The same heads-up-notification (HUN) behavior as regular notifications.
- A rail widget at the bottom of the screen will show when the navigation app is in the background.
NotificationCompat.Builder#setOnlyAlertOnce(true)
unless there is a significant navigation turn
event.
Summary
Nested classes | |
---|---|
class |
CarAppExtender.Builder
A builder of |
Public methods | |
---|---|
static
CarAppExtender.Builder
|
builder()
Creates a |
NotificationCompat.Builder
|
extend(NotificationCompat.Builder builder)
Applies car extensions to a notification that is being built. |
Inherited methods | |
---|---|
Public methods
builder
public static CarAppExtender.Builder builder ()
Creates a CarAppExtender.Builder
.
Returns | |
---|---|
CarAppExtender.Builder |
extend
public NotificationCompat.Builder extend (NotificationCompat.Builder builder)
Applies car extensions to a notification that is being built. This is typically called by
NotificationCompat.Builder.extend(android.support.v4.app.NotificationCompat.Extender)
.
Parameters | |
---|---|
builder |
NotificationCompat.Builder |
Returns | |
---|---|
NotificationCompat.Builder |
Throws | |
---|---|
NullPointerException |
if builder is null .
|
Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-15 UTC.