NotificationCompat.CarExtender

Added in 1.1.0

public final class NotificationCompat.CarExtender implements NotificationCompat.Extender


Helper class to add Android Auto extensions to notifications. To create a notification with car extensions:

  1. Create an NotificationCompat.Builder, setting any desired properties.
  2. Create a CarExtender.
  3. Set car-specific properties using the add and set methods of CarExtender.
  4. Call extend to apply the extensions to a notification.
  5. Post the notification to the notification system with the NotificationManagerCompat.notify(...) methods and not the NotificationManager.notify(...) methods.
Notification notification = new NotificationCompat.Builder(context)
        ...
        .extend(new CarExtender()
                .set*(...))
        .build();

Car extensions can be accessed on an existing notification by using the CarExtender(Notification) constructor, and then using the get methods to access values.

Summary

Nested types

This class is deprecated.

UnreadConversation is no longer supported.

Builder class for CarExtender.UnreadConversation objects.

Public constructors

Create a CarExtender with default options.

Create a CarExtender from the CarExtender options of an existing Notification.

Public methods

@NonNull NotificationCompat.Builder

Apply car extensions to a notification that is being built.

@ColorInt int

Gets the accent color.

@Nullable Bitmap

Gets the large icon used in this car notification, or null if no icon has been set.

@Nullable NotificationCompat.CarExtender.UnreadConversation

This method is deprecated.

UnreadConversation is no longer supported.

@NonNull NotificationCompat.CarExtender
setColor(@ColorInt int color)

Sets the accent color to use when Android Auto presents the notification.

@NonNull NotificationCompat.CarExtender

Sets the large icon of the car notification.

@NonNull NotificationCompat.CarExtender

This method is deprecated.

UnreadConversation is no longer supported.

Public constructors

CarExtender

Added in 1.1.0
public CarExtender()

Create a CarExtender with default options.

CarExtender

Added in 1.1.0
public CarExtender(@NonNull Notification notification)

Create a CarExtender from the CarExtender options of an existing Notification.

Parameters
@NonNull Notification notification

The notification from which to copy options.

Public methods

extend

Added in 1.15.0-rc01
public @NonNull NotificationCompat.Builder extend(@NonNull NotificationCompat.Builder builder)

Apply car extensions to a notification that is being built. This is typically called by the extend method of NotificationCompat.Builder.

getColor

Added in 1.1.0
public @ColorInt int getColor()

Gets the accent color.

See also
setColor

getLargeIcon

Added in 1.1.0
public @Nullable Bitmap getLargeIcon()

Gets the large icon used in this car notification, or null if no icon has been set.

Returns
@Nullable Bitmap

The large icon for the car notification.

See also
setLargeIcon

getUnreadConversation

Added in 1.1.0
Deprecated in 1.3.0
public @Nullable NotificationCompat.CarExtender.UnreadConversation getUnreadConversation()

Returns the unread conversation conveyed by this notification.

setColor

Added in 1.1.0
public @NonNull NotificationCompat.CarExtender setColor(@ColorInt int color)

Sets the accent color to use when Android Auto presents the notification. Android Auto uses the color set with setColor to accent the displayed notification. However, not all colors are acceptable in an automotive setting. This method can be used to override the color provided in the notification in such a situation.

setLargeIcon

Added in 1.1.0
public @NonNull NotificationCompat.CarExtender setLargeIcon(@Nullable Bitmap largeIcon)

Sets the large icon of the car notification. If no large icon is set in the extender, Android Auto will display the icon specified by setLargeIcon

Parameters
@Nullable Bitmap largeIcon

The large icon to use in the car notification.

Returns
@NonNull NotificationCompat.CarExtender

This object for method chaining.

setUnreadConversation

Added in 1.1.0
Deprecated in 1.3.0
public @NonNull NotificationCompat.CarExtender setUnreadConversation(
    @Nullable NotificationCompat.CarExtender.UnreadConversation unreadConversation
)

Sets the unread conversation in a message notification.

Parameters
@Nullable NotificationCompat.CarExtender.UnreadConversation unreadConversation

The unread part of the conversation this notification conveys.

Returns
@NonNull NotificationCompat.CarExtender

This object for method chaining.