# CarAppExtender

Artifact: [androidx.car.app:app](https://developer.android.com/jetpack/androidx/releases/car-app) [View Source](https://cs.android.com/search?q=file:androidx/car/app/notification/CarAppExtender.java+class:androidx.car.app.notification.CarAppExtender) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

*** ** * ** ***


```
public final class CarAppExtender implements NotificationCompat.Extender
```

<br />

*** ** * ** ***

Helper class to add car app extensions to notifications.

By default, notifications in a car screen have the properties provided by `https://developer.android.com/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 `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender`, even if the extender does not override any properties. To create a notification with car extensions:

1. Create a `https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder`, setting any desired properties.
2. Create a `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender.Builder`.
3. Set car-specific properties using the `set` methods of `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender.Builder`.
4. Create a `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender` by calling `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender.Builder#build()`.
5. Call `https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder#extend(androidx.core.app.NotificationCompat.Extender)` to apply the extensions to a notification.
6. Post the notification to the notification system with the `
   CarNotificationManager.notify(...)` methods. Do not use the `
   NotificationManager.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 `https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#IMPORTANCE_HIGH()`, or the priority is set to `https://developer.android.com/reference/androidx/core/app/NotificationCompat#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 `https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#IMPORTANCE_DEFAULT()` or above, or the priority is set to `https://developer.android.com/reference/androidx/core/app/NotificationCompat#PRIORITY_DEFAULT()` or above.
- The notification entry will show in the notification center for all priority levels.

Calling `https://developer.android.com/reference/androidx/car/app/notification/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)`.

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 `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender.Builder#setColor(androidx.car.app.model.CarColor)`.
- 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

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender.Builder` A builder of `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender`. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender#CarAppExtender(android.app.Notification)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/app/Notification.html notification)` Creates a `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender` from the `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender` of an existing notification. |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/app/Notification.Builder.html` | `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender#extend(android.app.Notification.Builder)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/app/Notification.Builder.html builder)` Applies car extensions to a notification that is being built. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder` | `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender#extend(androidx.core.app.NotificationCompat.Builder)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder builder)` Applies car extensions to a notification that is being built. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/android/app/Notification.Action.html>` | `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender#getActions()()` Returns the list of `https://developer.android.com/reference/android/app/Notification.Action.html` present on this car notification. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender#getChannelId()()` Returns the channel id of the notification channel to use in the car. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/car/app/model/CarColor` | `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender#getColor()()` Returns the background color of the notification or `null` if a default color is to be used. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/app/PendingIntent.html` | `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender#getContentIntent()()` Returns the `https://developer.android.com/reference/android/app/PendingIntent.html` to send when the notification is clicked in the car or `null` if not set. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/CharSequence.html` | `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender#getContentText()()` Returns the content text of the notification or `null` if not set. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/CharSequence.html` | `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender#getContentTitle()()` Returns the content title for the notification or `null` if not set. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/app/PendingIntent.html` | `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender#getDeleteIntent()()` Returns the `https://developer.android.com/reference/android/app/PendingIntent.html` to send when the notification is cleared by the user or `null` if not set. |
| `int` | `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender#getImportance()()` Returns the importance of the notification in the car screen. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/Bitmap.html` | `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender#getLargeIcon()()` Returns the large icon bitmap to display in the notification or `null` if not set. |
| `@https://developer.android.com/reference/androidx/annotation/DrawableRes int` | `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender#getSmallIcon()()` Returns the resource ID of the small icon drawable to use. |
| `static boolean` | `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender#isExtended(android.app.Notification)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/app/Notification.html notification)` Returns whether the given notification was extended with `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender`. |

## Public constructors

### CarAppExtender

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public CarAppExtender(@NonNull Notification notification)
```

Creates a `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender` from the `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender` of an existing notification.

## Public methods

### extend

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.7.0)

```
public @NonNull Notification.Builder extend(@NonNull Notification.Builder builder)
```

Applies car extensions to a notification that is being built.

For the most part, developers should be building notifications via `https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder` and not `https://developer.android.com/reference/android/app/Notification.Builder.html`; however, there may be reasons to not use the compat version, so this non-compat method is provided for convenience in those situations.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `builder` is `null` |

### extend

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public @NonNull NotificationCompat.Builder extend(@NonNull NotificationCompat.Builder builder)
```

Applies car extensions to a notification that is being built.

This is automatically called when the style is applied to the builder via `https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder#extend(androidx.core.app.NotificationCompat.Extender)` so this method does not need to be manually called.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `builder` is `null` |

### getActions

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public @NonNull List<Notification.Action> getActions()
```

Returns the list of `https://developer.android.com/reference/android/app/Notification.Action.html` present on this car notification.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender.Builder#addAction(int,java.lang.CharSequence,android.app.PendingIntent)` |   |

### getChannelId

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.1.0)

```
public @Nullable String getChannelId()
```

Returns the channel id of the notification channel to use in the car.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender.Builder#setChannelId(java.lang.String)` |   |

### getColor

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public @Nullable CarColor getColor()
```

Returns the background color of the notification or `null` if a default color is to be used.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender.Builder#setColor(androidx.car.app.model.CarColor)` |   |

### getContentIntent

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public @Nullable PendingIntent getContentIntent()
```

Returns the `https://developer.android.com/reference/android/app/PendingIntent.html` to send when the notification is clicked in the car or `null` if not set.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender.Builder#setContentIntent(android.app.PendingIntent)` |   |

### getContentText

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public @Nullable CharSequence getContentText()
```

Returns the content text of the notification or `null` if not set.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender.Builder#setContentText(java.lang.CharSequence)` |   |

### getContentTitle

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public @Nullable CharSequence getContentTitle()
```

Returns the content title for the notification or `null` if not set.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender.Builder#setContentTitle(java.lang.CharSequence)` |   |

### getDeleteIntent

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public @Nullable PendingIntent getDeleteIntent()
```

Returns the `https://developer.android.com/reference/android/app/PendingIntent.html` to send when the notification is cleared by the user or `null` if not set.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender.Builder#setDeleteIntent(android.app.PendingIntent)` |   |

### getImportance

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public int getImportance()
```

Returns the importance of the notification in the car screen.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender.Builder#setImportance(int)` |   |

### getLargeIcon

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public @Nullable Bitmap getLargeIcon()
```

Returns the large icon bitmap to display in the notification or `null` if not set.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender.Builder#setLargeIcon(android.graphics.Bitmap)` |   |

### getSmallIcon

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public @DrawableRes int getSmallIcon()
```

Returns the resource ID of the small icon drawable to use.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender.Builder#setSmallIcon(int)` |   |

### isExtended

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public static boolean isExtended(@NonNull Notification notification)
```

Returns whether the given notification was extended with `https://developer.android.com/reference/androidx/car/app/notification/CarAppExtender`.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `notification` is `null` |