public final class NotificationUtil
extends java.lang.Object
Notification
s.Modifier and Type | Class and Description |
---|---|
static interface |
NotificationUtil.Importance
Notification channel importance levels.
|
Modifier and Type | Field and Description |
---|---|
static int |
IMPORTANCE_DEFAULT |
static int |
IMPORTANCE_HIGH |
static int |
IMPORTANCE_LOW |
static int |
IMPORTANCE_MIN |
static int |
IMPORTANCE_NONE |
static int |
IMPORTANCE_UNSPECIFIED |
Modifier and Type | Method and Description |
---|---|
static void |
createNotificationChannel(android.content.Context context,
java.lang.String id,
int name,
int importance)
Creates a notification channel that notifications can be posted to.
|
static void |
setNotification(android.content.Context context,
int id,
android.app.Notification notification)
Post a notification to be shown in the status bar.
|
public static final int IMPORTANCE_UNSPECIFIED
NotificationManager.IMPORTANCE_UNSPECIFIED
,
Constant Field Valuespublic static final int IMPORTANCE_NONE
NotificationManager.IMPORTANCE_NONE
,
Constant Field Valuespublic static final int IMPORTANCE_MIN
NotificationManager.IMPORTANCE_MIN
,
Constant Field Valuespublic static final int IMPORTANCE_LOW
NotificationManager.IMPORTANCE_LOW
,
Constant Field Valuespublic static final int IMPORTANCE_DEFAULT
NotificationManager.IMPORTANCE_DEFAULT
,
Constant Field Valuespublic static final int IMPORTANCE_HIGH
NotificationManager.IMPORTANCE_HIGH
,
Constant Field Valuespublic static void createNotificationChannel(android.content.Context context, java.lang.String id, @StringRes int name, int importance)
NotificationChannel
and NotificationManager.createNotificationChannel(NotificationChannel)
for details.context
- A Context
to retrieve NotificationManager
.id
- The id of the channel. Must be unique per package. The value may be truncated if it
is too long.name
- A string resource identifier for the user visible name of the channel. You can
rename this channel when the system locale changes by listening for the Intent.ACTION_LOCALE_CHANGED
broadcast. The recommended maximum length is 40 characters;
the value may be truncated if it is too long.importance
- The importance of the channel. This controls how interruptive notifications
posted to this channel are. One of IMPORTANCE_UNSPECIFIED
, IMPORTANCE_NONE
, IMPORTANCE_MIN
, IMPORTANCE_LOW
, IMPORTANCE_DEFAULT
and IMPORTANCE_HIGH
.public static void setNotification(android.content.Context context, int id, @Nullable android.app.Notification notification)
notification
is null, then cancels a previously shown
notification.context
- A Context
to retrieve NotificationManager
.id
- An identifier for this notification unique within your application.notification
- A Notification
object describing what to show the user. If null,
then cancels a previously shown notification.