# NotificationUtil

# 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)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/common/util/NotificationUtil "View this page in Java")

<br />

```
@UnstableApi
class NotificationUtil
```

<br />

*** ** * ** ***

Utility methods for displaying[Notifications](https://developer.android.com/reference/android/app/Notification.html).

## Summary

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

|                                    ### Constants                                    |
|-------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [IMPORTANCE_DEFAULT](https://developer.android.com/reference/kotlin/androidx/media3/common/util/NotificationUtil#IMPORTANCE_DEFAULT())` = 3`             |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [IMPORTANCE_HIGH](https://developer.android.com/reference/kotlin/androidx/media3/common/util/NotificationUtil#IMPORTANCE_HIGH())` = 4`                   |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [IMPORTANCE_LOW](https://developer.android.com/reference/kotlin/androidx/media3/common/util/NotificationUtil#IMPORTANCE_LOW())` = 2`                     |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [IMPORTANCE_MIN](https://developer.android.com/reference/kotlin/androidx/media3/common/util/NotificationUtil#IMPORTANCE_MIN())` = 1`                     |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [IMPORTANCE_NONE](https://developer.android.com/reference/kotlin/androidx/media3/common/util/NotificationUtil#IMPORTANCE_NONE())` = 0`                   |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [IMPORTANCE_UNSPECIFIED](https://developer.android.com/reference/kotlin/androidx/media3/common/util/NotificationUtil#IMPORTANCE_UNSPECIFIED())` = -1000` |

|                                    ### Public functions                                     |
|---------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [createNotificationChannel](https://developer.android.com/reference/kotlin/androidx/media3/common/util/NotificationUtil#createNotificationChannel(android.content.Context,java.lang.String,int,int,int))`(` ` context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!,` ` id: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!,` ` nameResourceId: @`[StringRes](https://developer.android.com/reference/kotlin/androidx/annotation/StringRes)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` descriptionResourceId: @`[StringRes](https://developer.android.com/reference/kotlin/androidx/annotation/StringRes)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` @`[NotificationUtil.Importance](https://developer.android.com/reference/kotlin/androidx/media3/common/util/NotificationUtil.Importance)` importance: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) `)` Creates a notification channel that notifications can be posted to. |
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [setNotification](https://developer.android.com/reference/kotlin/androidx/media3/common/util/NotificationUtil#setNotification(android.content.Context,int,android.app.Notification))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!, id: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, notification: `[Notification](https://developer.android.com/reference/android/app/Notification.html)`?)` Post a notification to be shown in the status bar.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |

## Constants

### IMPORTANCE_DEFAULT

```
const val IMPORTANCE_DEFAULT = 3: Int
```  

|                                                        See also                                                         |
|-------------------------------------------------------------------------------------------------------------------------|---|
| [IMPORTANCE_DEFAULT](https://developer.android.com/reference/android/app/NotificationManager.html#IMPORTANCE_DEFAULT()) |   |

### IMPORTANCE_HIGH

```
const val IMPORTANCE_HIGH = 4: Int
```  

|                                                     See also                                                      |
|-------------------------------------------------------------------------------------------------------------------|---|
| [IMPORTANCE_HIGH](https://developer.android.com/reference/android/app/NotificationManager.html#IMPORTANCE_HIGH()) |   |

### IMPORTANCE_LOW

```
const val IMPORTANCE_LOW = 2: Int
```  

|                                                    See also                                                     |
|-----------------------------------------------------------------------------------------------------------------|---|
| [IMPORTANCE_LOW](https://developer.android.com/reference/android/app/NotificationManager.html#IMPORTANCE_LOW()) |   |

### IMPORTANCE_MIN

```
const val IMPORTANCE_MIN = 1: Int
```  

|                                                    See also                                                     |
|-----------------------------------------------------------------------------------------------------------------|---|
| [IMPORTANCE_MIN](https://developer.android.com/reference/android/app/NotificationManager.html#IMPORTANCE_MIN()) |   |

### IMPORTANCE_NONE

```
const val IMPORTANCE_NONE = 0: Int
```  

|                                                     See also                                                      |
|-------------------------------------------------------------------------------------------------------------------|---|
| [IMPORTANCE_NONE](https://developer.android.com/reference/android/app/NotificationManager.html#IMPORTANCE_NONE()) |   |

### IMPORTANCE_UNSPECIFIED

```
const val IMPORTANCE_UNSPECIFIED = -1000: Int
```  

|                                                            See also                                                             |
|---------------------------------------------------------------------------------------------------------------------------------|---|
| [IMPORTANCE_UNSPECIFIED](https://developer.android.com/reference/android/app/NotificationManager.html#IMPORTANCE_UNSPECIFIED()) |   |

## Public functions

### createNotificationChannel

```
java-static fun createNotificationChannel(
    context: Context!,
    id: String!,
    nameResourceId: @StringRes Int,
    descriptionResourceId: @StringRes Int,
    @NotificationUtil.Importance importance: Int
): Unit
```

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

|                                                                                                             Parameters                                                                                                             |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!`                                                                                                                                      | A[Context](https://developer.android.com/reference/android/content/Context.html).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `id: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!`                                                                                                                                         | The id of the channel. Must be unique per package. The value may be truncated if it's too long.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `nameResourceId: @`[StringRes](https://developer.android.com/reference/kotlin/androidx/annotation/StringRes)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                         | 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[ACTION_LOCALE_CHANGED](https://developer.android.com/reference/android/content/Intent.html#ACTION_LOCALE_CHANGED())broadcast.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `descriptionResourceId: @`[StringRes](https://developer.android.com/reference/kotlin/androidx/annotation/StringRes)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                  | 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[ACTION_LOCALE_CHANGED](https://developer.android.com/reference/android/content/Intent.html#ACTION_LOCALE_CHANGED())broadcast.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `@`[NotificationUtil.Importance](https://developer.android.com/reference/kotlin/androidx/media3/common/util/NotificationUtil.Importance)` importance: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The importance of the channel. This controls how interruptive notifications posted to this channel are. One of[IMPORTANCE_UNSPECIFIED](https://developer.android.com/reference/kotlin/androidx/media3/common/util/NotificationUtil#IMPORTANCE_UNSPECIFIED()),[IMPORTANCE_NONE](https://developer.android.com/reference/kotlin/androidx/media3/common/util/NotificationUtil#IMPORTANCE_NONE()),[IMPORTANCE_MIN](https://developer.android.com/reference/kotlin/androidx/media3/common/util/NotificationUtil#IMPORTANCE_MIN()),[IMPORTANCE_LOW](https://developer.android.com/reference/kotlin/androidx/media3/common/util/NotificationUtil#IMPORTANCE_LOW()),[IMPORTANCE_DEFAULT](https://developer.android.com/reference/kotlin/androidx/media3/common/util/NotificationUtil#IMPORTANCE_DEFAULT())and[IMPORTANCE_HIGH](https://developer.android.com/reference/kotlin/androidx/media3/common/util/NotificationUtil#IMPORTANCE_HIGH()). |

### setNotification

```
java-static fun setNotification(context: Context!, id: Int, notification: Notification?): Unit
```

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                                                |
|----------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!`            | A[Context](https://developer.android.com/reference/android/content/Context.html).                                                                   |
| `id: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                        | The notification id.                                                                                                                                |
| `notification: `[Notification](https://developer.android.com/reference/android/app/Notification.html)`?` | The[Notification](https://developer.android.com/reference/android/app/Notification.html)to post, or`null`to cancel a previously shown notification. |