# CarNotificationManager

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/CarNotificationManager.java+class:androidx.car.app.notification.CarNotificationManager) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.1.0)

*** ** * ** ***


```
public final class CarNotificationManager
```

<br />

*** ** * ** ***

A manager for car apps to send notifications. This class wraps a `https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat` to manage the actual sending of the `https://developer.android.com/reference/android/app/Notification.html`.

## Summary

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/car/app/notification/CarNotificationManager#areNotificationsEnabled()()` Returns whether notifications from the calling package are not blocked. |
| `void` | `https://developer.android.com/reference/androidx/car/app/notification/CarNotificationManager#cancel(int)(int id)` Cancels a previously shown notification. |
| `void` | `https://developer.android.com/reference/androidx/car/app/notification/CarNotificationManager#cancel(java.lang.String,int)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html tag, int id)` Cancels a previously shown notification. |
| `void` | `https://developer.android.com/reference/androidx/car/app/notification/CarNotificationManager#cancelAll()()` Cancels all previously shown notifications. |
| `void` | `https://developer.android.com/reference/androidx/car/app/notification/CarNotificationManager#createNotificationChannel(androidx.core.app.NotificationChannelCompat)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/app/NotificationChannelCompat channel)` Creates a notification channel that notifications can be posted to. |
| `void` | `https://developer.android.com/reference/androidx/car/app/notification/CarNotificationManager#createNotificationChannelGroup(androidx.core.app.NotificationChannelGroupCompat)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/app/NotificationChannelGroupCompat group )` Creates a group container for `https://developer.android.com/reference/android/app/NotificationChannel.html` objects. |
| `void` | `https://developer.android.com/reference/androidx/car/app/notification/CarNotificationManager#createNotificationChannelGroups(java.util.List<androidx.core.app.NotificationChannelGroupCompat>)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/core/app/NotificationChannelGroupCompat> groups )` Creates multiple notification channel groups. |
| `void` | `https://developer.android.com/reference/androidx/car/app/notification/CarNotificationManager#createNotificationChannels(java.util.List<androidx.core.app.NotificationChannelCompat>)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/core/app/NotificationChannelCompat> channels )` Creates multiple notification channels that different notifications can be posted to. |
| `void` | `https://developer.android.com/reference/androidx/car/app/notification/CarNotificationManager#deleteNotificationChannel(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html channelId)` Deletes the given notification channel. |
| `void` | `https://developer.android.com/reference/androidx/car/app/notification/CarNotificationManager#deleteNotificationChannelGroup(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html groupId)` Deletes the given notification channel group, and all notification channels that belong to it. |
| `void` | `https://developer.android.com/reference/androidx/car/app/notification/CarNotificationManager#deleteUnlistedNotificationChannels(java.util.Collection<java.lang.String>)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Collection.html<https://developer.android.com/reference/java/lang/String.html> channelIds )` Deletes notification channels for which ids are NOT given. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/notification/CarNotificationManager` | `https://developer.android.com/reference/androidx/car/app/notification/CarNotificationManager#from(android.content.Context)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context)` Returns a `https://developer.android.com/reference/androidx/car/app/notification/CarNotificationManager` instance for a provided context. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Set.html<https://developer.android.com/reference/java/lang/String.html>` | `https://developer.android.com/reference/androidx/car/app/notification/CarNotificationManager#getEnabledListenerPackages(android.content.Context)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context)` Get the set of packages that have an enabled notification listener component within them. |
| `int` | `https://developer.android.com/reference/androidx/car/app/notification/CarNotificationManager#getImportance()()` Returns the user specified importance for notifications from the calling package. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/core/app/NotificationChannelCompat` | `https://developer.android.com/reference/androidx/car/app/notification/CarNotificationManager#getNotificationChannel(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html channelId)` Returns the notification channel settings for a given channel id. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/core/app/NotificationChannelCompat` | `https://developer.android.com/reference/androidx/car/app/notification/CarNotificationManager#getNotificationChannel(java.lang.String,java.lang.String)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html channelId, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html conversationId )` Returns the notification channel settings for a given channel and `https://developer.android.com/reference/android/content/pm/ShortcutInfo.html#getId()`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/core/app/NotificationChannelGroupCompat` | `https://developer.android.com/reference/androidx/car/app/notification/CarNotificationManager#getNotificationChannelGroup(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html channelGroupId)` Returns the notification channel group settings for a given channel group id. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/core/app/NotificationChannelGroupCompat>` | `https://developer.android.com/reference/androidx/car/app/notification/CarNotificationManager#getNotificationChannelGroups()()` Returns all notification channel groups belonging to the calling app or an empty list on older SDKs which don't support Notification Channels. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/core/app/NotificationChannelCompat>` | `https://developer.android.com/reference/androidx/car/app/notification/CarNotificationManager#getNotificationChannels()()` Returns all notification channels belonging to the calling app or an empty list on older SDKs which don't support Notification Channels. |
| `void` | `https://developer.android.com/reference/androidx/car/app/notification/CarNotificationManager#notify(int,androidx.core.app.NotificationCompat.Builder)(int id, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder notification)` Posts a notification. |
| `void` | `https://developer.android.com/reference/androidx/car/app/notification/CarNotificationManager#notify(java.lang.String,int,androidx.core.app.NotificationCompat.Builder)( @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html tag, int id, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder notification )` Post a notification to be shown in the status bar, stream, etc. |

## Public methods

### areNotificationsEnabled

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

```
public boolean areNotificationsEnabled()
```

Returns whether notifications from the calling package are not blocked.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#areNotificationsEnabled()` |   |

### cancel

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

```
public void cancel(int id)
```

Cancels a previously shown notification.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#cancel(int)` |   |

### cancel

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

```
public void cancel(@Nullable String tag, int id)
```

Cancels a previously shown notification.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#cancel(java.lang.String,int)` |   |

### cancelAll

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

```
public void cancelAll()
```

Cancels all previously shown notifications.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#cancelAll()` |   |

### createNotificationChannel

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

```
public void createNotificationChannel(@NonNull NotificationChannelCompat channel)
```

Creates a notification channel that notifications can be posted to.

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

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#createNotificationChannel(androidx.core.app.NotificationChannelCompat)` |   |

### createNotificationChannelGroup

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

```
public void createNotificationChannelGroup(
    @NonNull NotificationChannelGroupCompat group
)
```

Creates a group container for `https://developer.android.com/reference/android/app/NotificationChannel.html` objects.

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

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#createNotificationChannelGroup(androidx.core.app.NotificationChannelGroupCompat)` |   |

### createNotificationChannelGroups

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

```
public void createNotificationChannelGroups(
    @NonNull List<NotificationChannelGroupCompat> groups
)
```

Creates multiple notification channel groups. See `https://developer.android.com/reference/androidx/car/app/notification/CarNotificationManager#createNotificationChannelGroup(androidx.core.app.NotificationChannelGroupCompat)`.

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

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#createNotificationChannelGroupsCompat(java.util.List<androidx.core.app.NotificationChannelGroupCompat>)` |   |

### createNotificationChannels

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

```
public void createNotificationChannels(
    @NonNull List<NotificationChannelCompat> channels
)
```

Creates multiple notification channels that different notifications can be posted to. See `https://developer.android.com/reference/androidx/car/app/notification/CarNotificationManager#createNotificationChannel(androidx.core.app.NotificationChannelCompat)`.

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

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#createNotificationChannelsCompat(java.util.List<androidx.core.app.NotificationChannelCompat>)` |   |

### deleteNotificationChannel

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

```
public void deleteNotificationChannel(@NonNull String channelId)
```

Deletes the given notification channel.

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

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#deleteNotificationChannel(java.lang.String)` |   |

### deleteNotificationChannelGroup

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

```
public void deleteNotificationChannelGroup(@NonNull String groupId)
```

Deletes the given notification channel group, and all notification channels that belong to it.

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

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#deleteNotificationChannelGroup(java.lang.String)` |   |

### deleteUnlistedNotificationChannels

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

```
public void deleteUnlistedNotificationChannels(
    @NonNull Collection<String> channelIds
)
```

Deletes notification channels for which ids are NOT given.

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

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#deleteUnlistedNotificationChannels(java.util.Collection<java.lang.String>)` |   |

### from

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

```
public static @NonNull CarNotificationManager from(@NonNull Context context)
```

Returns a `https://developer.android.com/reference/androidx/car/app/notification/CarNotificationManager` instance for a provided context.

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

### getEnabledListenerPackages

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

```
public static @NonNull Set<String> getEnabledListenerPackages(@NonNull Context context)
```

Get the set of packages that have an enabled notification listener component within them.

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

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#getEnabledListenerPackages(android.content.Context)` |   |

### getImportance

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

```
public int getImportance()
```

Returns the user specified importance for notifications from the calling package.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#getImportance()` |   |

### getNotificationChannel

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

```
public @Nullable NotificationChannelCompat getNotificationChannel(@NonNull String channelId)
```

Returns the notification channel settings for a given channel id.

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

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#getNotificationChannelCompat(java.lang.String)` |   |

### getNotificationChannel

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

```
public @Nullable NotificationChannelCompat getNotificationChannel(
    @NonNull String channelId,
    @NonNull String conversationId
)
```

Returns the notification channel settings for a given channel and `https://developer.android.com/reference/android/content/pm/ShortcutInfo.html#getId()`.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if either `channelId` of `conversationId` are ` null` |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#getNotificationChannelCompat(java.lang.String,java.lang.String)` |   |

### getNotificationChannelGroup

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

```
public @Nullable NotificationChannelGroupCompat getNotificationChannelGroup(@NonNull String channelGroupId)
```

Returns the notification channel group settings for a given channel group id.

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

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#getNotificationChannelGroupCompat(java.lang.String)` |   |

### getNotificationChannelGroups

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

```
public @NonNull List<NotificationChannelGroupCompat> getNotificationChannelGroups()
```

Returns all notification channel groups belonging to the calling app or an empty list on older SDKs which don't support Notification Channels.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#getNotificationChannelGroupsCompat()` |   |

### getNotificationChannels

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

```
public @NonNull List<NotificationChannelCompat> getNotificationChannels()
```

Returns all notification channels belonging to the calling app or an empty list on older SDKs which don't support Notification Channels.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#getNotificationChannelsCompat()` |   |

### notify

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

```
public void notify(int id, @NonNull NotificationCompat.Builder notification)
```

Posts a notification.

Callers are expected to extend the notification with CarAppExtender to ensure the notification will show up on all car environments. This method will extend the notification if it is not already extended for the car using a CarAppExtender.

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

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#notify(int,android.app.Notification)` |   |

### notify

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

```
public void notify(
    @Nullable String tag,
    int id,
    @NonNull NotificationCompat.Builder notification
)
```

Post a notification to be shown in the status bar, stream, etc.

Callers are expected to extend the notification with CarAppExtender to ensure the notification will show up on all car environments. This method will extend the notification if it is not already extended for the car using a CarAppExtender.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html tag` | the string identifier for a notification. Can be `null`. |
| `int id` | the ID of the notification. The pair (tag, id) must be unique within your app. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder notification` | the notification to post to the system |

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