CarAppExtender.Builder
public final class CarAppExtender.Builder
A builder of CarAppExtender.
Summary
Public methods |
|
|---|---|
@NonNull CarAppExtender.Builder |
addAction(@NonNull Notification.Action action)Adds an |
@NonNull CarAppExtender.Builder |
addAction(Adds an action to this notification. |
@NonNull CarAppExtender |
build()Constructs the |
@NonNull CarAppExtender.Builder |
setChannelId(@NonNull String channelId)For Android Automotive OS only, sets the channel id of the notification channel to be used in the car. |
@NonNull CarAppExtender.Builder |
Sets the background color of the notification in the car screen. |
@NonNull CarAppExtender.Builder |
setContentIntent(@NonNull PendingIntent contentIntent)Supplies a |
@NonNull CarAppExtender.Builder |
setContentText(@NonNull CharSequence contentText)Sets the content text of the notification in the car screen. |
@NonNull CarAppExtender.Builder |
setContentTitle(@NonNull CharSequence contentTitle)Sets the title of the notification in the car screen. |
@NonNull CarAppExtender.Builder |
setDeleteIntent(@NonNull PendingIntent deleteIntent)Supplies a |
@NonNull CarAppExtender.Builder |
setImportance(int importance)For Android Auto only, sets the importance of the notification in the car screen. |
@NonNull CarAppExtender.Builder |
setLargeIcon(@NonNull Bitmap bitmap)Sets the large icon of the notification in the car screen. |
@NonNull CarAppExtender.Builder |
setSmallIcon(int iconResId)Sets the small icon of the notification in the car screen. |
Public methods
addAction
public @NonNull CarAppExtender.Builder addAction(@NonNull Notification.Action action)
Adds an Action to this notification.
Actions are typically displayed by the system as a button adjacent to the notification content.
A notification may offer up to 2 actions. The system may not display some actions in the compact notification UI (e.g. heads-up-notifications).
If actions are added to a CarAppExtender, any actions directly added the notification being extended, for example via addAction, are ignored when the notification is shown in a car. Effectively, these actions override the notification's actions in the car environment. For example:
notificationBuilder.addAction(action1) carExtenderBuilder.addAction(action2) notificationBuilder.extend(carExtenderBuilder.build())
The mobile device will only show action1 and the car will only show action2.
addAction
public @NonNull CarAppExtender.Builder addAction(
@DrawableRes int icon,
@NonNull CharSequence title,
@NonNull PendingIntent intent
)
Adds an action to this notification.
Actions are typically displayed by the system as a button adjacent to the notification content.
A notification may offer up to 2 actions. The system may not display some actions in the compact notification UI (e.g. heads-up-notifications).
If actions are added to a CarAppExtender, any actions directly added the notification being extended, for example via addAction, are ignored when the notification is shown in a car. Effectively, these actions override the notification's actions in the car environment. For example:
notificationBuilder.addAction(action1) carExtenderBuilder.addAction(action2) notificationBuilder.extend(carExtenderBuilder.build())
The mobile device will only show action1 and the car will only show action2.
This method is equivalent to addAction for the car screen.
| Parameters | |
|---|---|
@DrawableRes int icon |
resource ID of a drawable that represents the action. In order to display the actions properly, a valid resource id for the icon must be provided |
@NonNull CharSequence title |
text describing the action |
@NonNull PendingIntent intent |
|
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
build
public @NonNull CarAppExtender build()
Constructs the CarAppExtender defined by this builder.
setChannelId
public @NonNull CarAppExtender.Builder setChannelId(@NonNull String channelId)
For Android Automotive OS only, sets the channel id of the notification channel to be used in the car.
This is used in the case where your notification is to have a different importance in the car then it does on the phone.
It is used for the same purposes you'd use setImportance for Auto.
| See also | |
|---|---|
setImportance |
setColor
public @NonNull CarAppExtender.Builder setColor(@NonNull CarColor color)
Sets the background color of the notification in the car screen.
This method is equivalent to setColor for the car screen.
This color is only used for navigation notifications. See the "Navigation" section of CarAppExtender for more details.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
setContentIntent
public @NonNull CarAppExtender.Builder setContentIntent(@NonNull PendingIntent contentIntent)
Supplies a PendingIntent to send when the notification is clicked in the car.
If not set, the notification's content intent will be used.
In the case of navigation notifications in the rail widget, this intent will be sent when the user taps on the rail widget.
This method is equivalent to setContentIntent for the car screen.
| Parameters | |
|---|---|
@NonNull PendingIntent contentIntent |
override for the notification's content intent. |
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
setContentText
public @NonNull CarAppExtender.Builder setContentText(@NonNull CharSequence contentText)
Sets the content text of the notification in the car screen.
This method is equivalent to setContentText for the car screen.
Spans are not supported in the input string and will be ignored.
| Parameters | |
|---|---|
@NonNull CharSequence contentText |
override for the notification's content text. If set to an empty string, it will be treated as if there is no context text |
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
setContentTitle
public @NonNull CarAppExtender.Builder setContentTitle(@NonNull CharSequence contentTitle)
Sets the title of the notification in the car screen.
This will be the most prominently displayed text in the car notification.
This method is equivalent to setContentTitle for the car screen.
Spans are not supported in the input string and will be ignored.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
setDeleteIntent
public @NonNull CarAppExtender.Builder setDeleteIntent(@NonNull PendingIntent deleteIntent)
Supplies a PendingIntent to send when the user clears the notification by either using the "clear all" functionality in the notification center, or tapping the individual "close" buttons on the notification in the car screen.
If not set, the notification's content intent will be used.
This method is equivalent to setDeleteIntent for the car screen.
| Parameters | |
|---|---|
@NonNull PendingIntent deleteIntent |
override for the notification's delete intent |
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
setImportance
public @NonNull CarAppExtender.Builder setImportance(int importance)
For Android Auto only, sets the importance of the notification in the car screen.
The default value is IMPORTANCE_UNSPECIFIED, and will not be used to override.
The importance is used to determine whether the notification will show as a HUN on the car screen. See the class description for more details.
See NotificationManagerCompat for all supported importance values.
| See also | |
|---|---|
setChannelId |
setLargeIcon
public @NonNull CarAppExtender.Builder setLargeIcon(@NonNull Bitmap bitmap)
Sets the large icon of the notification in the car screen.
This is used as the secondary icon to represent the notification in the notification center.
This method is equivalent to setLargeIcon for the car screen.
The large icon will be shown in the notification badge. If the large icon is not set in the CarAppExtender or the notification, the small icon will show instead.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
setSmallIcon
public @NonNull CarAppExtender.Builder setSmallIcon(int iconResId)
Sets the small icon of the notification in the car screen.
This is used as the primary icon to represent the notification.
This method is equivalent to setSmallIcon for the car screen.