NotificationManager.Policy


public static class NotificationManager.Policy
extends Object implements Parcelable

java.lang.Object
   ↳ android.app.NotificationManager.Policy


Notification policy configuration. Represents user-preferences for notification filtering.

Summary

Constants

int CONVERSATION_SENDERS_ANYONE

Used to indicate all conversations can bypass dnd.

int CONVERSATION_SENDERS_IMPORTANT

Used to indicate important conversations can bypass dnd.

int CONVERSATION_SENDERS_NONE

Used to indicate no conversations can bypass dnd.

int PRIORITY_CATEGORY_ALARMS

Alarms are prioritized

int PRIORITY_CATEGORY_CALLS

Calls are prioritized.

int PRIORITY_CATEGORY_CONVERSATIONS

Conversations are allowed through DND.

int PRIORITY_CATEGORY_EVENTS

Event notifications are prioritized.

int PRIORITY_CATEGORY_MEDIA

Media, game, voice navigation are prioritized

int PRIORITY_CATEGORY_MESSAGES

Message notifications are prioritized.

int PRIORITY_CATEGORY_REMINDERS

Reminder notifications are prioritized.

int PRIORITY_CATEGORY_REPEAT_CALLERS

Calls from repeat callers are prioritized.

int PRIORITY_CATEGORY_SYSTEM

System (catch-all for non-never suppressible sounds) are prioritized

int PRIORITY_SENDERS_ANY

Any sender is prioritized.

int PRIORITY_SENDERS_CONTACTS

Saved contacts are prioritized.

int PRIORITY_SENDERS_STARRED

Only starred contacts are prioritized.

int SUPPRESSED_EFFECT_AMBIENT

Whether notification intercepted by DND are prevented from appearing on ambient displays on devices that support ambient display.

int SUPPRESSED_EFFECT_BADGE

Whether badges from notifications intercepted by DND are blocked on devices that support badging.

int SUPPRESSED_EFFECT_FULL_SCREEN_INTENT

Whether full screen intents from notifications intercepted by DND are blocked.

int SUPPRESSED_EFFECT_LIGHTS

Whether notification lights from notifications intercepted by DND are blocked.

int SUPPRESSED_EFFECT_NOTIFICATION_LIST

Whether notification intercepted by DND are prevented from appearing in notification list views like the notification shade or lockscreen on devices that support those views.

int SUPPRESSED_EFFECT_PEEK

Whether notifications intercepted by DND are prevented from peeking.

int SUPPRESSED_EFFECT_SCREEN_OFF

This constant was deprecated in API level 28. use SUPPRESSED_EFFECT_FULL_SCREEN_INTENT and SUPPRESSED_EFFECT_AMBIENT and SUPPRESSED_EFFECT_LIGHTS individually.

int SUPPRESSED_EFFECT_SCREEN_ON

This constant was deprecated in API level 28. use SUPPRESSED_EFFECT_PEEK.

int SUPPRESSED_EFFECT_STATUS_BAR

Whether notifications intercepted by DND are prevented from appearing in the status bar, on devices that support status bars.

Inherited constants

Fields

public static final Creator<NotificationManager.Policy> CREATOR

public final int priorityCallSenders

Notification senders to prioritize for calls.

public final int priorityCategories

Notification categories to prioritize.

public final int priorityConversationSenders

Notification senders to prioritize for conversations.

public final int priorityMessageSenders

Notification senders to prioritize for messages.

public final int suppressedVisualEffects

Visual effects to suppress for a notification that is filtered by Do Not Disturb mode.

Public constructors

Policy(int priorityCategories, int priorityCallSenders, int priorityMessageSenders)

Constructs a policy for Do Not Disturb priority mode behavior.

Policy(int priorityCategories, int priorityCallSenders, int priorityMessageSenders, int suppressedVisualEffects)

Constructs a policy for Do Not Disturb priority mode behavior.

Policy(int priorityCategories, int priorityCallSenders, int priorityMessageSenders, int suppressedVisualEffects, int priorityConversationSenders)

Constructs a policy for Do Not Disturb priority mode behavior.

Public methods

int describeContents()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.

boolean equals(Object o)

Indicates whether some other object is "equal to" this one.

int hashCode()

Returns a hash code value for the object.

static String priorityCategoriesToString(int priorityCategories)
static String prioritySendersToString(int prioritySenders)
static String suppressedEffectsToString(int effects)
String toString()

Returns a string representation of the object.

void writeToParcel(Parcel dest, int flags)

Flatten this object in to a Parcel.

Inherited methods

Constants

CONVERSATION_SENDERS_ANYONE

Added in API level 30
public static final int CONVERSATION_SENDERS_ANYONE

Used to indicate all conversations can bypass dnd.

Constant Value: 1 (0x00000001)

CONVERSATION_SENDERS_IMPORTANT

Added in API level 30
public static final int CONVERSATION_SENDERS_IMPORTANT

Used to indicate important conversations can bypass dnd.

Constant Value: 2 (0x00000002)

CONVERSATION_SENDERS_NONE

Added in API level 30
public static final int CONVERSATION_SENDERS_NONE

Used to indicate no conversations can bypass dnd.

Constant Value: 3 (0x00000003)

PRIORITY_CATEGORY_ALARMS

Added in API level 28
public static final int PRIORITY_CATEGORY_ALARMS

Alarms are prioritized

Constant Value: 32 (0x00000020)

PRIORITY_CATEGORY_CALLS

Added in API level 23
public static final int PRIORITY_CATEGORY_CALLS

Calls are prioritized.

Constant Value: 8 (0x00000008)

PRIORITY_CATEGORY_CONVERSATIONS

Added in API level 30
public static final int PRIORITY_CATEGORY_CONVERSATIONS

Conversations are allowed through DND.

Constant Value: 256 (0x00000100)

PRIORITY_CATEGORY_EVENTS

Added in API level 23
public static final int PRIORITY_CATEGORY_EVENTS

Event notifications are prioritized.

Constant Value: 2 (0x00000002)

PRIORITY_CATEGORY_MEDIA

Added in API level 28
public static final int PRIORITY_CATEGORY_MEDIA

Media, game, voice navigation are prioritized

Constant Value: 64 (0x00000040)

PRIORITY_CATEGORY_MESSAGES

Added in API level 23
public static final int PRIORITY_CATEGORY_MESSAGES

Message notifications are prioritized.

Constant Value: 4 (0x00000004)

PRIORITY_CATEGORY_REMINDERS

Added in API level 23
public static final int PRIORITY_CATEGORY_REMINDERS

Reminder notifications are prioritized.

Constant Value: 1 (0x00000001)

PRIORITY_CATEGORY_REPEAT_CALLERS

Added in API level 23
public static final int PRIORITY_CATEGORY_REPEAT_CALLERS

Calls from repeat callers are prioritized.

Constant Value: 16 (0x00000010)

PRIORITY_CATEGORY_SYSTEM

Added in API level 28
public static final int PRIORITY_CATEGORY_SYSTEM

System (catch-all for non-never suppressible sounds) are prioritized

Constant Value: 128 (0x00000080)

PRIORITY_SENDERS_ANY

Added in API level 23
public static final int PRIORITY_SENDERS_ANY

Any sender is prioritized.

Constant Value: 0 (0x00000000)

PRIORITY_SENDERS_CONTACTS

Added in API level 23
public static final int PRIORITY_SENDERS_CONTACTS

Saved contacts are prioritized.

Constant Value: 1 (0x00000001)

PRIORITY_SENDERS_STARRED

Added in API level 23
public static final int PRIORITY_SENDERS_STARRED

Only starred contacts are prioritized.

Constant Value: 2 (0x00000002)

SUPPRESSED_EFFECT_AMBIENT

Added in API level 28
public static final int SUPPRESSED_EFFECT_AMBIENT

Whether notification intercepted by DND are prevented from appearing on ambient displays on devices that support ambient display.

Constant Value: 128 (0x00000080)

SUPPRESSED_EFFECT_BADGE

Added in API level 28
public static final int SUPPRESSED_EFFECT_BADGE

Whether badges from notifications intercepted by DND are blocked on devices that support badging.

Constant Value: 64 (0x00000040)

SUPPRESSED_EFFECT_FULL_SCREEN_INTENT

Added in API level 28
public static final int SUPPRESSED_EFFECT_FULL_SCREEN_INTENT

Whether full screen intents from notifications intercepted by DND are blocked.

Constant Value: 4 (0x00000004)

SUPPRESSED_EFFECT_LIGHTS

Added in API level 28
public static final int SUPPRESSED_EFFECT_LIGHTS

Whether notification lights from notifications intercepted by DND are blocked.

Constant Value: 8 (0x00000008)

SUPPRESSED_EFFECT_NOTIFICATION_LIST

Added in API level 28
public static final int SUPPRESSED_EFFECT_NOTIFICATION_LIST

Whether notification intercepted by DND are prevented from appearing in notification list views like the notification shade or lockscreen on devices that support those views.

Constant Value: 256 (0x00000100)

SUPPRESSED_EFFECT_PEEK

Added in API level 28
public static final int SUPPRESSED_EFFECT_PEEK

Whether notifications intercepted by DND are prevented from peeking.

Constant Value: 16 (0x00000010)

SUPPRESSED_EFFECT_SCREEN_OFF

Added in API level 24
Deprecated in API level 28
public static final int SUPPRESSED_EFFECT_SCREEN_OFF

This constant was deprecated in API level 28.
use SUPPRESSED_EFFECT_FULL_SCREEN_INTENT and SUPPRESSED_EFFECT_AMBIENT and SUPPRESSED_EFFECT_LIGHTS individually.

Whether notifications suppressed by DND should not interrupt visually (e.g. with notification lights or by turning the screen on) when the screen is off.

Constant Value: 1 (0x00000001)

SUPPRESSED_EFFECT_SCREEN_ON

Added in API level 24
Deprecated in API level 28
public static final int SUPPRESSED_EFFECT_SCREEN_ON

This constant was deprecated in API level 28.
use SUPPRESSED_EFFECT_PEEK.

Whether notifications suppressed by DND should not interrupt visually when the screen is on (e.g. by peeking onto the screen).

Constant Value: 2 (0x00000002)

SUPPRESSED_EFFECT_STATUS_BAR

Added in API level 28
public static final int SUPPRESSED_EFFECT_STATUS_BAR

Whether notifications intercepted by DND are prevented from appearing in the status bar, on devices that support status bars.

Constant Value: 32 (0x00000020)

Fields

CREATOR

Added in API level 23
public static final Creator<NotificationManager.Policy> CREATOR

priorityCallSenders

Added in API level 23
public final int priorityCallSenders

Notification senders to prioritize for calls. One of: PRIORITY_SENDERS_ANY, PRIORITY_SENDERS_CONTACTS, PRIORITY_SENDERS_STARRED
Value is PRIORITY_SENDERS_ANY, PRIORITY_SENDERS_CONTACTS, or PRIORITY_SENDERS_STARRED

priorityCategories

Added in API level 23
public final int priorityCategories

Notification categories to prioritize. Bitmask of PRIORITY_CATEGORY_* constants.

priorityConversationSenders

Added in API level 30
public final int priorityConversationSenders

Notification senders to prioritize for conversations. One of: CONVERSATION_SENDERS_NONE, CONVERSATION_SENDERS_IMPORTANT, CONVERSATION_SENDERS_ANYONE.
Value is CONVERSATION_SENDERS_ANYONE, CONVERSATION_SENDERS_IMPORTANT, or CONVERSATION_SENDERS_NONE

priorityMessageSenders

Added in API level 23
public final int priorityMessageSenders

Notification senders to prioritize for messages. One of: PRIORITY_SENDERS_ANY, PRIORITY_SENDERS_CONTACTS, PRIORITY_SENDERS_STARRED
Value is PRIORITY_SENDERS_ANY, PRIORITY_SENDERS_CONTACTS, or PRIORITY_SENDERS_STARRED

suppressedVisualEffects

Added in API level 24
public final int suppressedVisualEffects

Visual effects to suppress for a notification that is filtered by Do Not Disturb mode. Bitmask of SUPPRESSED_EFFECT_* constants.

Public constructors

Policy

Added in API level 23
public Policy (int priorityCategories, 
                int priorityCallSenders, 
                int priorityMessageSenders)

Constructs a policy for Do Not Disturb priority mode behavior.

Apps that target API levels below Build.VERSION_CODES#P cannot change user-designated values to allow or disallow Policy#PRIORITY_CATEGORY_ALARMS, Policy#PRIORITY_CATEGORY_SYSTEM, and Policy#PRIORITY_CATEGORY_MEDIA from bypassing dnd.

Parameters
priorityCategories int: bitmask of categories of notifications that can bypass DND.

priorityCallSenders int: which callers can bypass DND.

priorityMessageSenders int: which message senders can bypass DND.

Policy

Added in API level 24
public Policy (int priorityCategories, 
                int priorityCallSenders, 
                int priorityMessageSenders, 
                int suppressedVisualEffects)

Constructs a policy for Do Not Disturb priority mode behavior.

Apps that target API levels below Build.VERSION_CODES#R cannot change user-designated values to allow or disallow Policy#PRIORITY_CATEGORY_CONVERSATIONS, from bypassing dnd.

Additionally, apps that target API levels below Build.VERSION_CODES#P can only modify the SUPPRESSED_EFFECT_SCREEN_ON and SUPPRESSED_EFFECT_SCREEN_OFF bits of the suppressed visual effects field. All other suppressed effects will be ignored and reconstituted from the screen on and screen off values.

Apps that target Build.VERSION_CODES#P or above can set any suppressed visual effects. However, if any suppressed effects > SUPPRESSED_EFFECT_SCREEN_ON are set, SUPPRESSED_EFFECT_SCREEN_ON and SUPPRESSED_EFFECT_SCREEN_OFF will be ignored and reconstituted from the more specific suppressed visual effect bits. Apps should migrate to targeting specific effects instead of the deprecated SUPPRESSED_EFFECT_SCREEN_ON and SUPPRESSED_EFFECT_SCREEN_OFF effects.

Parameters
priorityCategories int: bitmask of categories of notifications that can bypass DND.

priorityCallSenders int: which callers can bypass DND.

priorityMessageSenders int: which message senders can bypass DND.

suppressedVisualEffects int: which visual interruptions should be suppressed from notifications that are filtered by DND.

Policy

Added in API level 30
public Policy (int priorityCategories, 
                int priorityCallSenders, 
                int priorityMessageSenders, 
                int suppressedVisualEffects, 
                int priorityConversationSenders)

Constructs a policy for Do Not Disturb priority mode behavior.

Apps that target API levels below Build.VERSION_CODES#P cannot change user-designated values to allow or disallow Policy#PRIORITY_CATEGORY_CONVERSATIONS from bypassing dnd. If you do need to change them, use a ZenPolicy associated with an AutomaticZenRule instead of changing the global setting.

Apps that target API levels below Build.VERSION_CODES#P cannot change user-designated values to allow or disallow Policy#PRIORITY_CATEGORY_ALARMS, Policy#PRIORITY_CATEGORY_SYSTEM, and Policy#PRIORITY_CATEGORY_MEDIA from bypassing dnd.

Additionally, apps that target API levels below Build.VERSION_CODES#P can only modify the SUPPRESSED_EFFECT_SCREEN_ON and SUPPRESSED_EFFECT_SCREEN_OFF bits of the suppressed visual effects field. All other suppressed effects will be ignored and reconstituted from the screen on and screen off values.

Apps that target Build.VERSION_CODES#P or above can set any suppressed visual effects. However, if any suppressed effects > SUPPRESSED_EFFECT_SCREEN_ON are set, SUPPRESSED_EFFECT_SCREEN_ON and SUPPRESSED_EFFECT_SCREEN_OFF will be ignored and reconstituted from the more specific suppressed visual effect bits. Apps should migrate to targeting specific effects instead of the deprecated SUPPRESSED_EFFECT_SCREEN_ON and SUPPRESSED_EFFECT_SCREEN_OFF effects.

Parameters
priorityCategories int: bitmask of categories of notifications that can bypass DND.

priorityCallSenders int: which callers can bypass DND. Value is PRIORITY_SENDERS_ANY, PRIORITY_SENDERS_CONTACTS, or PRIORITY_SENDERS_STARRED

priorityMessageSenders int: which message senders can bypass DND. Value is PRIORITY_SENDERS_ANY, PRIORITY_SENDERS_CONTACTS, or PRIORITY_SENDERS_STARRED

suppressedVisualEffects int: which visual interruptions should be suppressed from notifications that are filtered by DND.

priorityConversationSenders int: Value is CONVERSATION_SENDERS_ANYONE, CONVERSATION_SENDERS_IMPORTANT, or CONVERSATION_SENDERS_NONE

Public methods

describeContents

Added in API level 23
public int describeContents ()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. For example, if the object will include a file descriptor in the output of writeToParcel(android.os.Parcel, int), the return value of this method must include the CONTENTS_FILE_DESCRIPTOR bit.

Returns
int a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or CONTENTS_FILE_DESCRIPTOR

equals

Added in API level 23
public boolean equals (Object o)

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o Object: This value may be null.

Returns
boolean true if this object is the same as the obj argument; false otherwise.

hashCode

Added in API level 23
public int hashCode ()

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.

Returns
int a hash code value for this object.

priorityCategoriesToString

Added in API level 23
public static String priorityCategoriesToString (int priorityCategories)

Parameters
priorityCategories int

Returns
String

prioritySendersToString

Added in API level 23
public static String prioritySendersToString (int prioritySenders)

Parameters
prioritySenders int

Returns
String

suppressedEffectsToString

Added in API level 24
public static String suppressedEffectsToString (int effects)

Parameters
effects int

Returns
String

toString

Added in API level 23
public String toString ()

Returns a string representation of the object.

Returns
String a string representation of the object.

writeToParcel

Added in API level 23
public void writeToParcel (Parcel dest, 
                int flags)

Flatten this object in to a Parcel.

Parameters
dest Parcel: The Parcel in which the object should be written. This value cannot be null.

flags int: Additional flags about how the object should be written. May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE. Value is either 0 or a combination of Parcelable.PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES