NotificationManager
open class NotificationManager
| kotlin.Any | |
| ↳ | android.app.NotificationManager |
Class to notify the user of events that happen. This is how you tell the user that something has happened in the background. {@more} Notifications can take different forms:
- A persistent icon that goes in the status bar and is accessible through the launcher, (when the user selects it, a designated Intent can be launched),
- Turning on or flashing LEDs on the device, or
- Alerting the user by flashing the backlight, playing a sound, or vibrating.
Each of the notify methods takes an int id parameter and optionally a String tag parameter, which may be null. These parameters are used to form a pair (tag, id), or (null, id) if tag is unspecified. This pair identifies this notification from your app to the system, so that pair should be unique within your app. If you call one of the notify methods with a (tag, id) pair that is currently active and a new set of notification parameters, it will be updated. For example, if you pass a new status bar icon, the old icon in the status bar will be replaced with the new one. This is also the same tag and id you pass to the cancel(int) or cancel(java.lang.String,int) method to clear this notification.
Summary
Nested classes |
|
|---|---|
| open |
Notification policy configuration. |
Constants |
|
|---|---|
| static String |
Intent that is broadcast when an application is blocked or unblocked. |
| static String |
Activity Action: Launch an Automatic Zen Rule configuration screen |
| static String |
Intent that is broadcast when the status of an |
| static String |
Intent that is broadcast when the state of getCurrentInterruptionFilter() changes. |
| static String |
Intent that is broadcast when a |
| static String |
Intent that is broadcast when a |
| static String |
Intent that is broadcast when the state of |
| static String |
Intent that is broadcast when the state of getNotificationPolicy() changes. |
| static Int |
Constant value for |
| static Int |
Constant value for |
| static Int |
Constant value for |
| static Int |
Constant value for |
| static String |
Used as an optional string extra on |
| static String |
String extra for |
| static String |
Integer extra for |
| static String |
Extra for |
| static String |
Extra for |
| static String |
Extra for |
| static Int |
Default notification importance: shows everywhere, makes noise, but does not visually intrude. |
| static Int |
Higher notification importance: shows everywhere, makes noise and peeks. |
| static Int |
Low notification importance: Shows in the shade, and potentially in the status bar (see |
| static Int |
Unused. |
| static Int |
Min notification importance: only shows in the shade, below the fold. |
| static Int |
A notification with no importance: does not show in the shade. |
| static Int |
Value signifying that the user has not expressed an importance. |
| static Int |
|
| static Int |
|
| static Int |
|
| static Int |
|
| static Int |
|
| static String |
A required |
| static String |
An optional |
Public methods |
|
|---|---|
| open String! |
addAutomaticZenRule(automaticZenRule: AutomaticZenRule!)Creates the given zen rule. |
| open Boolean |
Gets whether all notifications posted by this app can appear outside of the notification shade, floating over other apps' content. |
| open Boolean |
Returns whether notifications from the calling package are blocked. |
| open Boolean |
Returns whether notifications from this package are temporarily hidden. |
| open Boolean |
canNotifyAsPackage(pkg: String)Returns whether you are allowed to post notifications on behalf of a given package, with |
| open Unit |
Cancels a previously posted notification. |
| open Unit |
Cancels a previously posted notification. |
| open Unit |
Cancel all previously shown notifications. |
| open Unit |
cancelAsPackage(targetPackage: String, tag: String?, id: Int)Cancels a previously posted notification. |
| open Unit |
createNotificationChannel(channel: NotificationChannel)Creates a notification channel that notifications can be posted to. |
| open Unit |
Creates a group container for |
| open Unit |
Creates multiple notification channel groups. |
| open Unit |
createNotificationChannels(channels: MutableList<NotificationChannel!>)Creates multiple notification channels that different notifications can be posted to. |
| open Unit |
deleteNotificationChannel(channelId: String!)Deletes the given notification channel. |
| open Unit |
deleteNotificationChannelGroup(groupId: String!)Deletes the given notification channel group, and all notification channels that belong to it. |
| open Array<StatusBarNotification!>! |
Recover a list of active notifications: ones that have been posted by the calling app that have not yet been dismissed by the user or |
| open AutomaticZenRule! |
getAutomaticZenRule(id: String!)Returns the AutomaticZenRule with the given id, if it exists and the caller has access. |
| open MutableMap<String!, AutomaticZenRule!>! |
Returns AutomaticZenRules owned by the caller. |
| open NotificationManager.Policy |
Returns the currently applied notification policy. |
| Int |
Gets the current notification interruption filter. |
| open Int |
Returns the user specified importance for notifications from the calling package. |
| open NotificationChannel! |
getNotificationChannel(channelId: String!)Returns the notification channel settings for a given channel id. |
| open NotificationChannel? |
getNotificationChannel(channelId: String, conversationId: String)Returns the notification channel settings for a given channel and |
| open NotificationChannelGroup! |
getNotificationChannelGroup(channelGroupId: String!)Returns the notification channel group settings for a given channel group id. |
| open MutableList<NotificationChannelGroup!>! |
Returns all notification channel groups belonging to the calling app. |
| open MutableList<NotificationChannel!>! |
Returns all notification channels belonging to the calling package. |
| open String? |
Returns the |
| open NotificationManager.Policy! |
Gets the current user-specified default notification policy. |
| open Boolean |
isNotificationListenerAccessGranted(listener: ComponentName!)Checks whether the user has approved a given |
| open Boolean |
Checks the ability to modify notification do not disturb policy for the calling package. |
| open Unit |
notify(id: Int, notification: Notification!)Post a notification to be shown in the status bar. |
| open Unit |
notify(tag: String!, id: Int, notification: Notification!)Posts a notification to be shown in the status bar. |
| open Unit |
notifyAsPackage(targetPackage: String, tag: String?, id: Int, notification: Notification)Posts a notification as a specified package to be shown in the status bar. |
| open Boolean |
removeAutomaticZenRule(id: String!)Deletes the automatic zen rule with the given id. |
| open Unit |
setAutomaticZenRuleState(id: String, condition: Condition)Informs the notification manager that the state of an |
| Unit |
setInterruptionFilter(interruptionFilter: Int)Sets the current notification interruption filter. |
| open Unit |
setNotificationDelegate(delegate: String?)Allows a package to post notifications on your behalf using |
| open Unit |
Sets the current notification policy. |
| open Boolean |
Returns whether the user wants silent notifications (see |
| open Boolean |
updateAutomaticZenRule(id: String!, automaticZenRule: AutomaticZenRule!)Updates the given zen rule. |
Constants
ACTION_APP_BLOCK_STATE_CHANGED
static val ACTION_APP_BLOCK_STATE_CHANGED: String
Intent that is broadcast when an application is blocked or unblocked. This broadcast is only sent to the app whose block state has changed. Input: nothing Output: EXTRA_BLOCKED_STATE
Value: "android.app.action.APP_BLOCK_STATE_CHANGED"
ACTION_AUTOMATIC_ZEN_RULE
static val ACTION_AUTOMATIC_ZEN_RULE: String
Activity Action: Launch an Automatic Zen Rule configuration screen
Input: Optionally, EXTRA_AUTOMATIC_RULE_ID, if the configuration screen for an existing rule should be displayed. If the rule id is missing or null, apps should display a configuration screen where users can create a new instance of the rule.
Output: Nothing
You can have multiple activities handling this intent, if you support multiple AutomaticZenRule. In order for the system to properly display all of your rule types so that users can create new instances or configure existing ones, you need to add some extra metadata (META_DATA_AUTOMATIC_RULE_TYPE) to your activity tag in your manifest. If you'd like to limit the number of rules a user can create from this flow, you can additionally optionally include META_DATA_RULE_INSTANCE_LIMIT. For example, <meta-data android:name="android.app.zen.automatic.ruleType" android:value="@string/my_condition_rule"> </meta-data> <meta-data android:name="android.app.zen.automatic.ruleInstanceLimit" android:value="1"> </meta-data>
Value: "android.app.action.AUTOMATIC_ZEN_RULE"
ACTION_AUTOMATIC_ZEN_RULE_STATUS_CHANGED
static val ACTION_AUTOMATIC_ZEN_RULE_STATUS_CHANGED: String
Intent that is broadcast when the status of an AutomaticZenRule has changed.
Use this to know whether you need to continue monitor to device state in order to provide up-to-date states (with setAutomaticZenRuleState(java.lang.String,android.service.notification.Condition)) for this rule.
EXTRA_AUTOMATIC_ZEN_RULE_ID Output: EXTRA_AUTOMATIC_ZEN_RULE_STATUS
Value: "android.app.action.AUTOMATIC_ZEN_RULE_STATUS_CHANGED"
ACTION_INTERRUPTION_FILTER_CHANGED
static val ACTION_INTERRUPTION_FILTER_CHANGED: String
Intent that is broadcast when the state of getCurrentInterruptionFilter() changes. This broadcast is only sent to registered receivers.
Value: "android.app.action.INTERRUPTION_FILTER_CHANGED"
ACTION_NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED
static val ACTION_NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED: String
Intent that is broadcast when a NotificationChannel is blocked (when NotificationChannel#getImportance() is IMPORTANCE_NONE) or unblocked (when NotificationChannel#getImportance() is anything other than IMPORTANCE_NONE). This broadcast is only sent to the app that owns the channel that has changed. Input: nothing Output: EXTRA_NOTIFICATION_CHANNEL_ID Output: EXTRA_BLOCKED_STATE
Value: "android.app.action.NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED"
ACTION_NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED
static val ACTION_NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED: String
Intent that is broadcast when a NotificationChannelGroup is NotificationChannelGroup#isBlocked() or unblocked. This broadcast is only sent to the app that owns the channel group that has changed. Input: nothing Output: EXTRA_NOTIFICATION_CHANNEL_GROUP_ID Output: EXTRA_BLOCKED_STATE
Value: "android.app.action.NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED"
ACTION_NOTIFICATION_POLICY_ACCESS_GRANTED_CHANGED
static val ACTION_NOTIFICATION_POLICY_ACCESS_GRANTED_CHANGED: String
Intent that is broadcast when the state of isNotificationPolicyAccessGranted() changes. This broadcast is only sent to registered receivers, and only to the apps that have changed.
Value: "android.app.action.NOTIFICATION_POLICY_ACCESS_GRANTED_CHANGED"
ACTION_NOTIFICATION_POLICY_CHANGED
static val ACTION_NOTIFICATION_POLICY_CHANGED: String
Intent that is broadcast when the state of getNotificationPolicy() changes. This broadcast is only sent to registered receivers.
Value: "android.app.action.NOTIFICATION_POLICY_CHANGED"
AUTOMATIC_RULE_STATUS_DISABLED
static val AUTOMATIC_RULE_STATUS_DISABLED: Int
Constant value for EXTRA_AUTOMATIC_ZEN_RULE_STATUS - the given rule currently exists but is disabled. You do not need to continue to provide state changes via setAutomaticZenRuleState(java.lang.String,android.service.notification.Condition) until the rule is reenabled.
Value: 2
AUTOMATIC_RULE_STATUS_ENABLED
static val AUTOMATIC_RULE_STATUS_ENABLED: Int
Constant value for EXTRA_AUTOMATIC_ZEN_RULE_STATUS - the given rule currently exists and is enabled. You should continue to provide state changes via setAutomaticZenRuleState(java.lang.String,android.service.notification.Condition).
Value: 1
AUTOMATIC_RULE_STATUS_REMOVED
static val AUTOMATIC_RULE_STATUS_REMOVED: Int
Constant value for EXTRA_AUTOMATIC_ZEN_RULE_STATUS - the given rule has been deleted. Further calls to setAutomaticZenRuleState(java.lang.String,android.service.notification.Condition) will be ignored.
Value: 3
AUTOMATIC_RULE_STATUS_UNKNOWN
static val AUTOMATIC_RULE_STATUS_UNKNOWN: Int
Constant value for EXTRA_AUTOMATIC_ZEN_RULE_STATUS - the current status of the rule is unknown at your target sdk version, and you should continue to provide state changes via setAutomaticZenRuleState(java.lang.String,android.service.notification.Condition).
Value: -1
EXTRA_AUTOMATIC_RULE_ID
static val EXTRA_AUTOMATIC_RULE_ID: String
Used as an optional string extra on ACTION_AUTOMATIC_ZEN_RULE intents. If provided, contains the id of the AutomaticZenRule (as returned from NotificationManager#addAutomaticZenRule(AutomaticZenRule)) for which configuration settings should be displayed.
Value: "android.app.extra.AUTOMATIC_RULE_ID"
EXTRA_AUTOMATIC_ZEN_RULE_ID
static val EXTRA_AUTOMATIC_ZEN_RULE_ID: String
String extra for ACTION_AUTOMATIC_ZEN_RULE_STATUS_CHANGED containing the id of the AutomaticZenRule (see addAutomaticZenRule(android.app.AutomaticZenRule)) that has changed.
Value: "android.app.extra.AUTOMATIC_ZEN_RULE_ID"
EXTRA_AUTOMATIC_ZEN_RULE_STATUS
static val EXTRA_AUTOMATIC_ZEN_RULE_STATUS: String
Integer extra for ACTION_AUTOMATIC_ZEN_RULE_STATUS_CHANGED containing the state of the AutomaticZenRule.
The value will be one of AUTOMATIC_RULE_STATUS_ENABLED, AUTOMATIC_RULE_STATUS_DISABLED, AUTOMATIC_RULE_STATUS_REMOVED, AUTOMATIC_RULE_STATUS_UNKNOWN.
Value: "android.app.extra.AUTOMATIC_ZEN_RULE_STATUS"
EXTRA_BLOCKED_STATE
static val EXTRA_BLOCKED_STATE: String
Extra for ACTION_NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED or ACTION_NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED containing the new blocked state as a boolean. The value will be true if this channel or group is now blocked and false if this channel or group is now unblocked.
Value: "android.app.extra.BLOCKED_STATE"
EXTRA_NOTIFICATION_CHANNEL_GROUP_ID
static val EXTRA_NOTIFICATION_CHANNEL_GROUP_ID: String
Extra for ACTION_NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED containing the id of the NotificationChannelGroup which has a new blocked state. The value will be the NotificationChannelGroup#getId() of the group.
Value: "android.app.extra.NOTIFICATION_CHANNEL_GROUP_ID"
EXTRA_NOTIFICATION_CHANNEL_ID
static val EXTRA_NOTIFICATION_CHANNEL_ID: String
Extra for ACTION_NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED containing the id of the NotificationChannel which has a new blocked state. The value will be the NotificationChannel#getId() of the channel.
Value: "android.app.extra.NOTIFICATION_CHANNEL_ID"
IMPORTANCE_DEFAULT
static val IMPORTANCE_DEFAULT: Int
Default notification importance: shows everywhere, makes noise, but does not visually intrude.
Value: 3
IMPORTANCE_HIGH
static val IMPORTANCE_HIGH: Int
Higher notification importance: shows everywhere, makes noise and peeks. May use full screen intents.
Value: 4
IMPORTANCE_LOW
static val IMPORTANCE_LOW: Int
Low notification importance: Shows in the shade, and potentially in the status bar (see shouldHideSilentStatusBarIcons()), but is not audibly intrusive.
Value: 2
IMPORTANCE_MIN
static val IMPORTANCE_MIN: Int
Min notification importance: only shows in the shade, below the fold. This should not be used with Service#startForeground(int, Notification) since a foreground service is supposed to be something the user cares about so it does not make semantic sense to mark its notification as minimum importance. If you do this as of Android version android.os.Build.VERSION_CODES#O, the system will show a higher-priority notification about your app running in the background.
Value: 1
IMPORTANCE_NONE
static val IMPORTANCE_NONE: Int
A notification with no importance: does not show in the shade.
Value: 0
IMPORTANCE_UNSPECIFIED
static val IMPORTANCE_UNSPECIFIED: Int
Value signifying that the user has not expressed an importance. This value is for persisting preferences, and should never be associated with an actual notification.
Value: -1000
INTERRUPTION_FILTER_ALARMS
static val INTERRUPTION_FILTER_ALARMS: Int
Interruption filter constant - Alarms only interruption filter - all notifications except those of category Notification#CATEGORY_ALARM are suppressed. Some audio streams are muted.
Value: 4
INTERRUPTION_FILTER_ALL
static val INTERRUPTION_FILTER_ALL: Int
Interruption filter constant - Normal interruption filter - no notifications are suppressed.
Value: 1
INTERRUPTION_FILTER_NONE
static val INTERRUPTION_FILTER_NONE: Int
Interruption filter constant - No interruptions filter - all notifications are suppressed and all audio streams (except those used for phone calls) and vibrations are muted.
Value: 3
INTERRUPTION_FILTER_PRIORITY
static val INTERRUPTION_FILTER_PRIORITY: Int
Interruption filter constant - Priority interruption filter - all notifications are suppressed except those that match the priority criteria. Some audio streams are muted. See Policy#priorityCallSenders, Policy#priorityCategories, Policy#priorityMessageSenders to define or query this criteria. Users can additionally specify packages that can bypass this interruption filter.
Value: 2
INTERRUPTION_FILTER_UNKNOWN
static val INTERRUPTION_FILTER_UNKNOWN: Int
Interruption filter constant - returned when the value is unavailable for any reason.
Value: 0
META_DATA_AUTOMATIC_RULE_TYPE
static val META_DATA_AUTOMATIC_RULE_TYPE: String
A required meta-data tag for activities that handle ACTION_AUTOMATIC_ZEN_RULE. This tag should contain a localized name of the type of the zen rule provided by the activity.
Value: "android.service.zen.automatic.ruleType"
META_DATA_RULE_INSTANCE_LIMIT
static val META_DATA_RULE_INSTANCE_LIMIT: String
An optional meta-data tag for activities that handle ACTION_AUTOMATIC_ZEN_RULE. This tag should contain the maximum number of rule instances that can be created for this rule type. Omit or enter a value <= 0 to allow unlimited instances.
Value: "android.service.zen.automatic.ruleInstanceLimit"
Public methods
addAutomaticZenRule
open fun addAutomaticZenRule(automaticZenRule: AutomaticZenRule!): String!
Creates the given zen rule.
Throws a SecurityException if policy access is not granted to this package. See isNotificationPolicyAccessGranted.
| Parameters | |
|---|---|
automaticZenRule |
AutomaticZenRule!: the rule to create. |
| Return | |
|---|---|
String! |
The id of the newly created rule; null if the rule could not be created. |
areBubblesAllowed
open fun areBubblesAllowed(): Boolean
Gets whether all notifications posted by this app can appear outside of the notification shade, floating over other apps' content.
This value will be ignored for notifications that are posted to channels that do not allow bubbles (NotificationChannel#canBubble().
areNotificationsEnabled
open fun areNotificationsEnabled(): Boolean
Returns whether notifications from the calling package are blocked.
areNotificationsPaused
open fun areNotificationsPaused(): Boolean
Returns whether notifications from this package are temporarily hidden. This could be done because the package was marked as distracting to the user via PackageManager#setDistractingPackageRestrictions(String[], int) or because the package is PackageManager#setPackagesSuspended(String[], boolean, PersistableBundle, PersistableBundle, SuspendDialogInfo) suspended.
canNotifyAsPackage
open fun canNotifyAsPackage(pkg: String): Boolean
Returns whether you are allowed to post notifications on behalf of a given package, with notifyAsPackage(java.lang.String,java.lang.String,int,android.app.Notification). See setNotificationDelegate(java.lang.String).
| Parameters | |
|---|---|
pkg |
String: This value cannot be null. |
cancel
open fun cancel(id: Int): Unit
Cancels a previously posted notification.
If the notification does not currently represent a Service#startForeground(int, Notification), it will be removed from the UI and live notification listeners will be informed so they can remove the notification from their UIs.
cancel
open fun cancel(
tag: String?,
id: Int
): Unit
Cancels a previously posted notification.
If the notification does not currently represent a Service#startForeground(int, Notification), it will be removed from the UI and live notification listeners will be informed so they can remove the notification from their UIs.
| Parameters | |
|---|---|
tag |
String?: This value may be null. |
cancelAll
open fun cancelAll(): Unit
Cancel all previously shown notifications. See cancel for the detailed behavior.
cancelAsPackage
open fun cancelAsPackage(
targetPackage: String,
tag: String?,
id: Int
): Unit
Cancels a previously posted notification.
If the notification does not currently represent a Service#startForeground(int, Notification), it will be removed from the UI and live notification listeners will be informed so they can remove the notification from their UIs.
This method may be used by a notification delegate to cancel notifications that they have posted via notifyAsPackage(java.lang.String,java.lang.String,int,android.app.Notification).
| Parameters | |
|---|---|
targetPackage |
String: The package to cancel the notification as. If this package is not your package, you can only cancel notifications you posted with |
createNotificationChannel
open fun createNotificationChannel(channel: NotificationChannel): Unit
Creates a notification channel that notifications can be posted to. This can also be used to restore a deleted channel and to update an existing channel's name, description, group, and/or importance.
The name and description should only be changed if the locale changes or in response to the user renaming this channel. For example, if a user has a channel named 'John Doe' that represents messages from a 'John Doe', and 'John Doe' changes his name to 'John Smith,' the channel can be renamed to match.
The importance of an existing channel will only be changed if the new importance is lower than the current value and the user has not altered any settings on this channel.
The group an existing channel will only be changed if the channel does not already belong to a group. All other fields are ignored for channels that already exist.
| Parameters | |
|---|---|
channel |
NotificationChannel: the channel to create. Note that the created channel may differ from this value. If the provided channel is malformed, a RemoteException will be thrown. This value cannot be null. |
createNotificationChannelGroup
open fun createNotificationChannelGroup(group: NotificationChannelGroup): Unit
Creates a group container for NotificationChannel objects. This can be used to rename an existing group.
Group information is only used for presentation, not for behavior. Groups are optional for channels, and you can have a mix of channels that belong to groups and channels that do not.
For example, if your application supports multiple accounts, and those accounts will have similar channels, you can create a group for each account with account specific labels instead of appending account information to each channel's label.
| Parameters | |
|---|---|
group |
NotificationChannelGroup: The group to create This value cannot be null. |
createNotificationChannelGroups
open fun createNotificationChannelGroups(groups: MutableList<NotificationChannelGroup!>): Unit
Creates multiple notification channel groups.
| Parameters | |
|---|---|
groups |
MutableList<NotificationChannelGroup!>: The list of groups to create This value cannot be null. |
createNotificationChannels
open fun createNotificationChannels(channels: MutableList<NotificationChannel!>): Unit
Creates multiple notification channels that different notifications can be posted to. See createNotificationChannel(android.app.NotificationChannel).
| Parameters | |
|---|---|
channels |
MutableList<NotificationChannel!>: the list of channels to attempt to create. This value cannot be null. |
deleteNotificationChannel
open fun deleteNotificationChannel(channelId: String!): Unit
Deletes the given notification channel.
If you create a new channel with this same id, the deleted channel will be un-deleted with all of the same settings it had before it was deleted.
deleteNotificationChannelGroup
open fun deleteNotificationChannelGroup(groupId: String!): Unit
Deletes the given notification channel group, and all notification channels that belong to it.
getActiveNotifications
open fun getActiveNotifications(): Array<StatusBarNotification!>!
Recover a list of active notifications: ones that have been posted by the calling app that have not yet been dismissed by the user or cancel(java.lang.String,int)ed by the app.
StatusBarNotification object, including the original tag and id supplied to notify() (via StatusBarNotification#getTag() and StatusBarNotification#getId()) as well as a copy of the original Notification object (via StatusBarNotification#getNotification()).
From Build.VERSION_CODES#Q, will also return notifications you've posted as an app's notification delegate via NotificationManager#notifyAsPackage(String, String, int, Notification).
| Return | |
|---|---|
Array<StatusBarNotification!>! |
An array of StatusBarNotification. |
getAutomaticZenRule
open fun getAutomaticZenRule(id: String!): AutomaticZenRule!
Returns the AutomaticZenRule with the given id, if it exists and the caller has access.
Throws a SecurityException if policy access is not granted to this package. See isNotificationPolicyAccessGranted.
Returns null if there are no zen rules that match the given id, or if the calling package doesn't own the matching rule. See AutomaticZenRule#getOwner.
getAutomaticZenRules
open fun getAutomaticZenRules(): MutableMap<String!, AutomaticZenRule!>!
Returns AutomaticZenRules owned by the caller.
Throws a SecurityException if policy access is not granted to this package. See isNotificationPolicyAccessGranted.
getConsolidatedNotificationPolicy
open fun getConsolidatedNotificationPolicy(): NotificationManager.Policy
Returns the currently applied notification policy.
If getCurrentInterruptionFilter is equal to INTERRUPTION_FILTER_ALL, then the consolidated notification policy will match the default notification policy returned by getNotificationPolicy.
| Return | |
|---|---|
NotificationManager.Policy |
This value cannot be null. |
getCurrentInterruptionFilter
fun getCurrentInterruptionFilter(): Int
Gets the current notification interruption filter.
The interruption filter defines which notifications are allowed to interrupt the user (e.g. via sound & vibration) and is applied globally.
getImportance
open fun getImportance(): Int
Returns the user specified importance for notifications from the calling package.
getNotificationChannel
open fun getNotificationChannel(channelId: String!): NotificationChannel!
Returns the notification channel settings for a given channel id.
The channel must belong to your package, or to a package you are an approved notification delegate for (see canNotifyAsPackage(java.lang.String)), or it will not be returned. To query a channel as a notification delegate, call this method from a context created for that package (see Context#createPackageContext(String, int)).
getNotificationChannel
open fun getNotificationChannel(
channelId: String,
conversationId: String
): NotificationChannel?
Returns the notification channel settings for a given channel and ShortcutInfo#getId().
The channel must belong to your package, or to a package you are an approved notification delegate for (see canNotifyAsPackage(java.lang.String)), or it will not be returned. To query a channel as a notification delegate, call this method from a context created for that package (see Context#createPackageContext(String, int)).
| Parameters | |
|---|---|
channelId |
String: This value cannot be null. |
conversationId |
String: This value cannot be null. |
| Return | |
|---|---|
NotificationChannel? |
This value may be null. |
getNotificationChannelGroup
open fun getNotificationChannelGroup(channelGroupId: String!): NotificationChannelGroup!
Returns the notification channel group settings for a given channel group id. The channel group must belong to your package, or null will be returned.
getNotificationChannelGroups
open fun getNotificationChannelGroups(): MutableList<NotificationChannelGroup!>!
Returns all notification channel groups belonging to the calling app.
getNotificationChannels
open fun getNotificationChannels(): MutableList<NotificationChannel!>!
Returns all notification channels belonging to the calling package.
Approved notification delegates (see canNotifyAsPackage(java.lang.String)) can query notification channels belonging to packages they are the delegate for. To do so, call this method from a context created for that package (see Context#createPackageContext(String, int)).
getNotificationDelegate
open fun getNotificationDelegate(): String?
Returns the delegate that can post notifications on your behalf, if there currently is one.
| Return | |
|---|---|
String? |
This value may be null. |
getNotificationPolicy
open fun getNotificationPolicy(): NotificationManager.Policy!
Gets the current user-specified default notification policy.
isNotificationListenerAccessGranted
open fun isNotificationListenerAccessGranted(listener: ComponentName!): Boolean
Checks whether the user has approved a given android.service.notification.NotificationListenerService.
The listener service must belong to the calling app.
Apps can request notification listener access by sending the user to the activity that matches the system intent action android.provider.Settings#ACTION_NOTIFICATION_LISTENER_SETTINGS.
isNotificationPolicyAccessGranted
open fun isNotificationPolicyAccessGranted(): Boolean
Checks the ability to modify notification do not disturb policy for the calling package.
Returns true if the calling package can modify notification policy.
Apps can request policy access by sending the user to the activity that matches the system intent action android.provider.Settings#ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS.
Use ACTION_NOTIFICATION_POLICY_ACCESS_GRANTED_CHANGED to listen for user grant or denial of this access.
notify
open fun notify(
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.
| Parameters | |
|---|---|
id |
Int: An identifier for this notification unique within your application. |
notification |
Notification!: A Notification object describing what to show the user. Must not be null. |
notify
open fun notify(
tag: String!,
id: Int,
notification: Notification!
): Unit
Posts a notification to be shown in the status bar. If a notification with the same tag and id has already been posted by your application and has not yet been canceled, it will be replaced by the updated information. All listener services will be granted Intent#FLAG_GRANT_READ_URI_PERMISSION access to any Uri provided on this notification or the NotificationChannel this notification is posted to using Context#grantUriPermission(String, Uri, int). Permission will be revoked when the notification is canceled, or you can revoke permissions with Context#revokeUriPermission(Uri, int).
| Parameters | |
|---|---|
tag |
String!: A string identifier for this notification. May be null. |
id |
Int: An identifier for this notification. The pair (tag, id) must be unique within your application. |
notification |
Notification!: A Notification object describing what to show the user. Must not be null. |
notifyAsPackage
open fun notifyAsPackage(
targetPackage: String,
tag: String?,
id: Int,
notification: Notification
): Unit
Posts a notification as a specified package to be shown in the status bar. If a notification with the same tag and id has already been posted for that package and has not yet been canceled, it will be replaced by the updated information. All listener services will be granted Intent#FLAG_GRANT_READ_URI_PERMISSION access to any Uri provided on this notification or the NotificationChannel this notification is posted to using Context#grantUriPermission(String, Uri, int). Permission will be revoked when the notification is canceled, or you can revoke permissions with Context#revokeUriPermission(Uri, int).
| Parameters | |
|---|---|
targetPackage |
String: The package to post the notification as. The package must have granted you access to post notifications on their behalf with setNotificationDelegate(java.lang.String). This value cannot be null. |
tag |
String?: A string identifier for this notification. May be null. This value may be null. |
id |
Int: An identifier for this notification. The pair (tag, id) must be unique within your application. |
notification |
Notification: A Notification object describing what to show the user. Must not be null. This value cannot be null. |
removeAutomaticZenRule
open fun removeAutomaticZenRule(id: String!): Boolean
Deletes the automatic zen rule with the given id.
Throws a SecurityException if policy access is not granted to this package. See isNotificationPolicyAccessGranted.
Callers can only delete rules that they own. See AutomaticZenRule#getOwner.
| Parameters | |
|---|---|
id |
String!: the id of the rule to delete. |
| Return | |
|---|---|
Boolean |
Whether the rule was successfully deleted. |
setAutomaticZenRuleState
open fun setAutomaticZenRuleState(
id: String,
condition: Condition
): Unit
Informs the notification manager that the state of an AutomaticZenRule has changed. Use this method to put the system into Do Not Disturb mode or request that it exits Do Not Disturb mode. The calling app must own the provided android.app.AutomaticZenRule.
This method can be used in conjunction with or as a replacement to android.service.notification.ConditionProviderService#notifyCondition(Condition).
| Parameters | |
|---|---|
id |
String: The id of the rule whose state should change This value cannot be null. |
condition |
Condition: The new state of this rule This value cannot be null. |
setInterruptionFilter
fun setInterruptionFilter(interruptionFilter: Int): Unit
Sets the current notification interruption filter.
The interruption filter defines which notifications are allowed to interrupt the user (e.g. via sound & vibration) and is applied globally.
Only available if policy access is granted to this package. See isNotificationPolicyAccessGranted.
setNotificationDelegate
open fun setNotificationDelegate(delegate: String?): Unit
Allows a package to post notifications on your behalf using notifyAsPackage(java.lang.String,java.lang.String,int,android.app.Notification). This can be used to allow persistent processes to post notifications based on messages received on your behalf from the cloud, without your process having to wake up. You can check if you have an allowed delegate with getNotificationDelegate() and revoke your delegate by passing null to this method.
| Parameters | |
|---|---|
delegate |
String?: Package name of the app which can send notifications on your behalf. This value may be null. |
setNotificationPolicy
open fun setNotificationPolicy(policy: NotificationManager.Policy): Unit
Sets the current notification policy.
Only available if policy access is granted to this package. See isNotificationPolicyAccessGranted.
| Parameters | |
|---|---|
policy |
NotificationManager.Policy: The new desired policy. This value cannot be null. |
shouldHideSilentStatusBarIcons
open fun shouldHideSilentStatusBarIcons(): Boolean
Returns whether the user wants silent notifications (see IMPORTANCE_LOW to appear in the status bar.
Only available for notification.
updateAutomaticZenRule
open fun updateAutomaticZenRule(
id: String!,
automaticZenRule: AutomaticZenRule!
): Boolean
Updates the given zen rule.
Throws a SecurityException if policy access is not granted to this package. See isNotificationPolicyAccessGranted.
Callers can only update rules that they own. See AutomaticZenRule#getOwner.
| Parameters | |
|---|---|
id |
String!: The id of the rule to update |
automaticZenRule |
AutomaticZenRule!: the rule to update. |
| Return | |
|---|---|
Boolean |
Whether the rule was successfully updated. |