# NotificationUtil

Artifact: [androidx.media3:media3-common](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/common/util/NotificationUtil.java+class:androidx.media3.common.util.NotificationUtil)

*** ** * ** ***


```
@UnstableApi
public final class NotificationUtil
```

<br />

*** ** * ** ***

Utility methods for displaying `https://developer.android.com/reference/android/app/Notification.html`.

## Summary

| ### Nested types |
|---|
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#SOURCE) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = https://developer.android.com/reference/java/lang/annotation/ElementType.html#TYPE_USE) @https://developer.android.com/reference/androidx/annotation/IntDef(value = ) public annotation https://developer.android.com/reference/androidx/media3/common/util/NotificationUtil.Importance` Notification channel importance levels. |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/media3/common/util/NotificationUtil#IMPORTANCE_DEFAULT() = 3` |
| `static final int` | `https://developer.android.com/reference/androidx/media3/common/util/NotificationUtil#IMPORTANCE_HIGH() = 4` |
| `static final int` | `https://developer.android.com/reference/androidx/media3/common/util/NotificationUtil#IMPORTANCE_LOW() = 2` |
| `static final int` | `https://developer.android.com/reference/androidx/media3/common/util/NotificationUtil#IMPORTANCE_MIN() = 1` |
| `static final int` | `https://developer.android.com/reference/androidx/media3/common/util/NotificationUtil#IMPORTANCE_NONE() = 0` |
| `static final int` | `https://developer.android.com/reference/androidx/media3/common/util/NotificationUtil#IMPORTANCE_UNSPECIFIED() = -1000` |

| ### Public methods |
|---|---|
| `static void` | `https://developer.android.com/reference/androidx/media3/common/util/NotificationUtil#createNotificationChannel(android.content.Context,java.lang.String,int,int,int)( https://developer.android.com/reference/android/content/Context.html context, https://developer.android.com/reference/java/lang/String.html id, @https://developer.android.com/reference/androidx/annotation/StringRes int nameResourceId, @https://developer.android.com/reference/androidx/annotation/StringRes int descriptionResourceId, @https://developer.android.com/reference/androidx/media3/common/util/NotificationUtil.Importance int importance )` Creates a notification channel that notifications can be posted to. |
| `static void` | `https://developer.android.com/reference/androidx/media3/common/util/NotificationUtil#setNotification(android.content.Context,int,android.app.Notification)( https://developer.android.com/reference/android/content/Context.html context, int id, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/android/app/Notification.html notification )` Post a notification to be shown in the status bar. |

## Constants

### IMPORTANCE_DEFAULT

```
public static final int IMPORTANCE_DEFAULT = 3
```

| See also |
|---|---|
| `https://developer.android.com/reference/android/app/NotificationManager.html#IMPORTANCE_DEFAULT` |   |

### IMPORTANCE_HIGH

```
public static final int IMPORTANCE_HIGH = 4
```

| See also |
|---|---|
| `https://developer.android.com/reference/android/app/NotificationManager.html#IMPORTANCE_HIGH` |   |

### IMPORTANCE_LOW

```
public static final int IMPORTANCE_LOW = 2
```

| See also |
|---|---|
| `https://developer.android.com/reference/android/app/NotificationManager.html#IMPORTANCE_LOW` |   |

### IMPORTANCE_MIN

```
public static final int IMPORTANCE_MIN = 1
```

| See also |
|---|---|
| `https://developer.android.com/reference/android/app/NotificationManager.html#IMPORTANCE_MIN` |   |

### IMPORTANCE_NONE

```
public static final int IMPORTANCE_NONE = 0
```

| See also |
|---|---|
| `https://developer.android.com/reference/android/app/NotificationManager.html#IMPORTANCE_NONE` |   |

### IMPORTANCE_UNSPECIFIED

```
public static final int IMPORTANCE_UNSPECIFIED = -1000
```

| See also |
|---|---|
| `https://developer.android.com/reference/android/app/NotificationManager.html#IMPORTANCE_UNSPECIFIED` |   |

## Public methods

### createNotificationChannel

```
public static void createNotificationChannel(
    Context context,
    String id,
    @StringRes int nameResourceId,
    @StringRes int descriptionResourceId,
    @NotificationUtil.Importance int importance
)
```

Creates a notification channel that notifications can be posted to. See `https://developer.android.com/reference/android/app/NotificationChannel.html` and `https://developer.android.com/reference/android/app/NotificationManager.html#createNotificationChannel(android.app.NotificationChannel)` for details.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html context` | A `https://developer.android.com/reference/android/content/Context.html`. |
| `https://developer.android.com/reference/java/lang/String.html id` | The id of the channel. Must be unique per package. The value may be truncated if it's too long. |
| `@https://developer.android.com/reference/androidx/annotation/StringRes int nameResourceId` | A string resource identifier for the user visible name of the channel. The recommended maximum length is 40 characters. The string may be truncated if it's too long. You can rename the channel when the system locale changes by listening for the `https://developer.android.com/reference/android/content/Intent.html#ACTION_LOCALE_CHANGED` broadcast. |
| `@https://developer.android.com/reference/androidx/annotation/StringRes int descriptionResourceId` | A string resource identifier for the user visible description of the channel, or 0 if no description is provided. The recommended maximum length is 300 characters. The value may be truncated if it is too long. You can change the description of the channel when the system locale changes by listening for the `https://developer.android.com/reference/android/content/Intent.html#ACTION_LOCALE_CHANGED` broadcast. |
| `@https://developer.android.com/reference/androidx/media3/common/util/NotificationUtil.Importance int importance` | The importance of the channel. This controls how interruptive notifications posted to this channel are. One of `https://developer.android.com/reference/androidx/media3/common/util/NotificationUtil#IMPORTANCE_UNSPECIFIED()`, `https://developer.android.com/reference/androidx/media3/common/util/NotificationUtil#IMPORTANCE_NONE()`, `https://developer.android.com/reference/androidx/media3/common/util/NotificationUtil#IMPORTANCE_MIN()`, `https://developer.android.com/reference/androidx/media3/common/util/NotificationUtil#IMPORTANCE_LOW()`, `https://developer.android.com/reference/androidx/media3/common/util/NotificationUtil#IMPORTANCE_DEFAULT()` and `https://developer.android.com/reference/androidx/media3/common/util/NotificationUtil#IMPORTANCE_HIGH()`. |

### setNotification

```
public static void setNotification(
    Context context,
    int id,
    @Nullable Notification notification
)
```

Post a notification to be shown in the status bar. If a notification with the same id has already been posted by your application and has not yet been canceled, it will be replaced by the updated information. If `notification` is `null` then any notification previously shown with the specified id will be cancelled.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html context` | A `https://developer.android.com/reference/android/content/Context.html`. |
| `int id` | The notification id. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/android/app/Notification.html notification` | The `https://developer.android.com/reference/android/app/Notification.html` to post, or `null` to cancel a previously shown notification. |