ZenPolicy.Builder


public static final class ZenPolicy.Builder
extends Object

java.lang.Object
   ↳ android.service.notification.ZenPolicy.Builder


Builder class for ZenPolicy objects. Provides a convenient way to set the various fields of a ZenPolicy. If a field is not set, it is (@link STATE_UNSET} and will not change the current set policy.

Summary

Public constructors

Builder()

Public methods

ZenPolicy.Builder allowAlarms(boolean allow)

Whether to allow notifications with category Notification#CATEGORY_ALARM to play sounds and visually appear or to intercept them when DND is active.

ZenPolicy.Builder allowAllSounds()

Allows all notifications to bypass DND and unmutes all streams.

ZenPolicy.Builder allowCalls(int audienceType)

Whether to allow notifications with category Notification#CATEGORY_CALL that match audienceType to play sounds and visually appear or to intercept them when DND is active.

ZenPolicy.Builder allowConversations(int audienceType)

Whether to allow conversation notifications (see NotificationChannel#setConversationId(String, String)) that match audienceType to play sounds and visually appear or to intercept them when DND is active.

ZenPolicy.Builder allowEvents(boolean allow)

Whether to allow notifications with category Notification#CATEGORY_EVENT to play sounds and visually appear or to intercept them when DND is active.

ZenPolicy.Builder allowMedia(boolean allow)

Whether to allow media notifications to play sounds and visually appear or to intercept them when DND is active.

ZenPolicy.Builder allowMessages(int audienceType)

Whether to allow notifications with category Notification#CATEGORY_MESSAGE that match audienceType to play sounds and visually appear or to intercept them when DND is active.

ZenPolicy.Builder allowPriorityChannels(boolean allow)

Set whether priority channels are permitted to break through DND.

ZenPolicy.Builder allowReminders(boolean allow)

Whether to allow notifications with category Notification#CATEGORY_REMINDER to play sounds and visually appear or to intercept them when DND is active.

ZenPolicy.Builder allowRepeatCallers(boolean allow)

Whether to allow repeat callers (notifications with category Notification#CATEGORY_CALL that have recently called to play sounds and visually appear.

ZenPolicy.Builder allowSystem(boolean allow)

Whether to allow system sounds to play when DND is active.

ZenPolicy build()

Builds the current ZenPolicy.

ZenPolicy.Builder disallowAllSounds()

Intercepts all notifications and prevents them from playing sounds when DND is active.

ZenPolicy.Builder hideAllVisualEffects()

Disallows notifications intercepted by DND from showing when DND is active.

ZenPolicy.Builder showAllVisualEffects()

Allows notifications intercepted by DND to show on all surfaces when DND is active.

ZenPolicy.Builder showBadges(boolean show)

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

ZenPolicy.Builder showFullScreenIntent(boolean show)

Whether full screen intents that are intercepted by DND are shown.

ZenPolicy.Builder showInAmbientDisplay(boolean show)

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

ZenPolicy.Builder showInNotificationList(boolean show)

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.

ZenPolicy.Builder showLights(boolean show)

Whether notification lights from notifications intercepted by DND are blocked.

ZenPolicy.Builder showPeeking(boolean show)

Whether notifications intercepted by DND are prevented from peeking.

ZenPolicy.Builder showStatusBarIcons(boolean show)

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

Inherited methods

Public constructors

Builder

Added in API level 29
public Builder ()

Public methods

allowAlarms

Added in API level 29
public ZenPolicy.Builder allowAlarms (boolean allow)

Whether to allow notifications with category Notification#CATEGORY_ALARM to play sounds and visually appear or to intercept them when DND is active. Disallowing alarms will mute the alarm stream when DND is active.

Parameters
allow boolean

Returns
ZenPolicy.Builder This value cannot be null.

allowAllSounds

Added in API level 29
public ZenPolicy.Builder allowAllSounds ()

Allows all notifications to bypass DND and unmutes all streams.

Returns
ZenPolicy.Builder This value cannot be null.

allowCalls

Added in API level 29
public ZenPolicy.Builder allowCalls (int audienceType)

Whether to allow notifications with category Notification#CATEGORY_CALL that match audienceType to play sounds and visually appear or to intercept them when DND is active.

Parameters
audienceType int: callers that are allowed to bypass DND Value is ZenPolicy.PEOPLE_TYPE_UNSET, ZenPolicy.PEOPLE_TYPE_ANYONE, ZenPolicy.PEOPLE_TYPE_CONTACTS, ZenPolicy.PEOPLE_TYPE_STARRED, or ZenPolicy.PEOPLE_TYPE_NONE

Returns
ZenPolicy.Builder This value cannot be null.

allowConversations

Added in API level 30
public ZenPolicy.Builder allowConversations (int audienceType)

Whether to allow conversation notifications (see NotificationChannel#setConversationId(String, String)) that match audienceType to play sounds and visually appear or to intercept them when DND is active.

Parameters
audienceType int: callers that are allowed to bypass DND Value is ZenPolicy.CONVERSATION_SENDERS_UNSET, ZenPolicy.CONVERSATION_SENDERS_ANYONE, ZenPolicy.CONVERSATION_SENDERS_IMPORTANT, or ZenPolicy.CONVERSATION_SENDERS_NONE

Returns
ZenPolicy.Builder This value cannot be null.

allowEvents

Added in API level 29
public ZenPolicy.Builder allowEvents (boolean allow)

Whether to allow notifications with category Notification#CATEGORY_EVENT to play sounds and visually appear or to intercept them when DND is active.

Parameters
allow boolean

Returns
ZenPolicy.Builder This value cannot be null.

allowMedia

Added in API level 29
public ZenPolicy.Builder allowMedia (boolean allow)

Whether to allow media notifications to play sounds and visually appear or to intercept them when DND is active. Disallowing media will mute the media stream when DND is active.

Parameters
allow boolean

Returns
ZenPolicy.Builder This value cannot be null.

allowMessages

Added in API level 29
public ZenPolicy.Builder allowMessages (int audienceType)

Whether to allow notifications with category Notification#CATEGORY_MESSAGE that match audienceType to play sounds and visually appear or to intercept them when DND is active.

Parameters
audienceType int: message senders that are allowed to bypass DND Value is ZenPolicy.PEOPLE_TYPE_UNSET, ZenPolicy.PEOPLE_TYPE_ANYONE, ZenPolicy.PEOPLE_TYPE_CONTACTS, ZenPolicy.PEOPLE_TYPE_STARRED, or ZenPolicy.PEOPLE_TYPE_NONE

Returns
ZenPolicy.Builder This value cannot be null.

allowPriorityChannels

Added in API level 35
public ZenPolicy.Builder allowPriorityChannels (boolean allow)

Set whether priority channels are permitted to break through DND.

Parameters
allow boolean

Returns
ZenPolicy.Builder This value cannot be null.

allowReminders

Added in API level 29
public ZenPolicy.Builder allowReminders (boolean allow)

Whether to allow notifications with category Notification#CATEGORY_REMINDER to play sounds and visually appear or to intercept them when DND is active.

Parameters
allow boolean

Returns
ZenPolicy.Builder This value cannot be null.

allowRepeatCallers

Added in API level 29
public ZenPolicy.Builder allowRepeatCallers (boolean allow)

Whether to allow repeat callers (notifications with category Notification#CATEGORY_CALL that have recently called to play sounds and visually appear.

Parameters
allow boolean

Returns
ZenPolicy.Builder This value cannot be null.

allowSystem

Added in API level 29
public ZenPolicy.Builder allowSystem (boolean allow)

Whether to allow system sounds to play when DND is active. Disallowing system sounds will mute the system stream when DND is active.

Parameters
allow boolean

Returns
ZenPolicy.Builder This value cannot be null.

build

Added in API level 29
public ZenPolicy build ()

Builds the current ZenPolicy.

Returns
ZenPolicy This value cannot be null.

disallowAllSounds

Added in API level 29
public ZenPolicy.Builder disallowAllSounds ()

Intercepts all notifications and prevents them from playing sounds when DND is active. Also mutes alarm, system and media streams. Notification channels can still play sounds only if they can bypass DND. If no channels can bypass DND, the ringer stream is also muted.

Returns
ZenPolicy.Builder This value cannot be null.

hideAllVisualEffects

Added in API level 29
public ZenPolicy.Builder hideAllVisualEffects ()

Disallows notifications intercepted by DND from showing when DND is active.

Returns
ZenPolicy.Builder This value cannot be null.

showAllVisualEffects

Added in API level 29
public ZenPolicy.Builder showAllVisualEffects ()

Allows notifications intercepted by DND to show on all surfaces when DND is active.

Returns
ZenPolicy.Builder This value cannot be null.

showBadges

Added in API level 29
public ZenPolicy.Builder showBadges (boolean show)

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

Parameters
show boolean

Returns
ZenPolicy.Builder This value cannot be null.

showFullScreenIntent

Added in API level 29
public ZenPolicy.Builder showFullScreenIntent (boolean show)

Whether full screen intents that are intercepted by DND are shown.

Parameters
show boolean

Returns
ZenPolicy.Builder This value cannot be null.

showInAmbientDisplay

Added in API level 29
public ZenPolicy.Builder showInAmbientDisplay (boolean show)

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

Parameters
show boolean

Returns
ZenPolicy.Builder This value cannot be null.

showInNotificationList

Added in API level 29
public ZenPolicy.Builder showInNotificationList (boolean show)

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.

Parameters
show boolean

Returns
ZenPolicy.Builder This value cannot be null.

showLights

Added in API level 29
public ZenPolicy.Builder showLights (boolean show)

Whether notification lights from notifications intercepted by DND are blocked.

Parameters
show boolean

Returns
ZenPolicy.Builder This value cannot be null.

showPeeking

Added in API level 29
public ZenPolicy.Builder showPeeking (boolean show)

Whether notifications intercepted by DND are prevented from peeking.

Parameters
show boolean

Returns
ZenPolicy.Builder This value cannot be null.

showStatusBarIcons

Added in API level 29
public ZenPolicy.Builder showStatusBarIcons (boolean show)

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

Parameters
show boolean

Returns
ZenPolicy.Builder This value cannot be null.