NotificationUtil
@UnstableApi
public final class NotificationUtil
Utility methods for displaying Notifications.
Summary
Nested types |
|---|
@DocumentedNotification channel importance levels. |
Constants |
|
|---|---|
static final int |
|
static final int |
IMPORTANCE_HIGH = 4 |
static final int |
IMPORTANCE_LOW = 2 |
static final int |
IMPORTANCE_MIN = 1 |
static final int |
IMPORTANCE_NONE = 0 |
static final int |
IMPORTANCE_UNSPECIFIED = -1000 |
Public methods |
|
|---|---|
static void |
createNotificationChannel(Creates a notification channel that notifications can be posted to. |
static void |
setNotification(Post a notification to be shown in the status bar. |
Constants
IMPORTANCE_UNSPECIFIED
public static final int IMPORTANCE_UNSPECIFIED = -1000
| See also | |
|---|---|
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 NotificationChannel and createNotificationChannel for details.
| Parameters | |
|---|---|
Context context |
A |
String id |
The id of the channel. Must be unique per package. The value may be truncated if it's too long. |
@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 |
@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 |
@NotificationUtil.Importance int importance |
The importance of the channel. This controls how interruptive notifications posted to this channel are. One of |
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 | |
|---|---|
Context context |
A |
int id |
The notification id. |
@Nullable Notification notification |
The |