public class

NotificationCompat.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.core.app.NotificationCompat.Builder

Overview

Builder class for NotificationCompat objects. Allows easier control over all the flags, as well as help constructing the typical notification layouts.

On platform versions that don't offer expanded notifications, methods that depend on expanded notifications have no effect.

For example, action buttons won't appear on platforms prior to Android 4.1. Action buttons depend on expanded notifications, which are only available in Android 4.1 and later.

For this reason, you should always ensure that UI controls in a notification are also available in an in your app, and you should always start that when users click the notification. To do this, use the setContentIntent() method.

Summary

Fields
public java.util.ArrayList<NotificationCompat.Action>mActions

public ContextmContext

public java.util.ArrayList<java.lang.String>mPeople

public java.util.ArrayList<Person>mPersonList

Constructors
publicBuilder(Context context)

publicBuilder(Context context, Notification notification)

Creates a NotificationCompat.Builder which can be used to build a notification that is equivalent to the given one, such that updates can be made to an existing notification with the NotitifactionCompat.Builder API.

publicBuilder(Context context, java.lang.String channelId)

Constructor.

Methods
public NotificationCompat.BuilderaddAction(int icon, java.lang.CharSequence title, PendingIntent intent)

Add an action to this notification.

public NotificationCompat.BuilderaddAction(NotificationCompat.Action action)

Add an action to this notification.

public NotificationCompat.BuilderaddExtras(Bundle extras)

Merge additional metadata into this notification.

public NotificationCompat.BuilderaddInvisibleAction(int icon, java.lang.CharSequence title, PendingIntent intent)

Add an invisible action to this notification.

public NotificationCompat.BuilderaddInvisibleAction(NotificationCompat.Action action)

Add an invisible action to this notification.

public NotificationCompat.BuilderaddPerson(Person person)

Add a person that is relevant to this notification.

public NotificationCompat.BuilderaddPerson(java.lang.String uri)

Add a person that is relevant to this notification.

public Notificationbuild()

Combine all of the options that have been set and return a new Notification object.

public NotificationCompat.BuilderclearActions()

Clear any actions added via NotificationCompat.Builder.addAction(int, CharSequence, PendingIntent)

public NotificationCompat.BuilderclearInvisibleActions()

Clear any invisible actions added via NotificationCompat.Builder.addInvisibleAction(int, CharSequence, PendingIntent)

public NotificationCompat.BuilderclearPeople()

Clear any people added via either NotificationCompat.Builder.addPerson(Person) or NotificationCompat.Builder.addPerson(String)

public RemoteViewscreateBigContentView()

Construct a RemoteViews for the final big notification layout.

public RemoteViewscreateContentView()

Construct a RemoteViews for the final notification layout.

public RemoteViewscreateHeadsUpContentView()

Construct a RemoteViews for the final heads-up notification layout.

public NotificationCompat.Builderextend(NotificationCompat.Extender extender)

Apply an extender to this notification builder.

public RemoteViewsgetBigContentView()

public NotificationCompat.BubbleMetadatagetBubbleMetadata()

public intgetColor()

public RemoteViewsgetContentView()

public BundlegetExtras()

Get the current metadata Bundle used by this notification Builder.

public intgetForegroundServiceBehavior()

public RemoteViewsgetHeadsUpContentView()

public NotificationgetNotification()

public intgetPriority()

public longgetWhenIfShowing()

return when if it is showing or 0 otherwise

protected static java.lang.CharSequencelimitCharSequenceLength(java.lang.CharSequence cs)

public NotificationCompat.BuildersetAllowSystemGeneratedContextualActions(boolean allowed)

Determines whether the platform can generate contextual actions for a notification.

public NotificationCompat.BuildersetAutoCancel(boolean autoCancel)

Setting this flag will make it so the notification is automatically canceled when the user clicks it in the panel.

public NotificationCompat.BuildersetBadgeIconType(int icon)

Sets which icon to display as a badge for this notification.

public NotificationCompat.BuildersetBubbleMetadata(NotificationCompat.BubbleMetadata data)

Sets the NotificationCompat.BubbleMetadata that will be used to display app content in a floating window over the existing foreground activity.

public NotificationCompat.BuildersetCategory(java.lang.String category)

Set the notification category.

public NotificationCompat.BuildersetChannelId(java.lang.String channelId)

Specifies the channel the notification should be delivered on.

public NotificationCompat.BuildersetChronometerCountDown(boolean countsDown)

Sets the Chronometer to count down instead of counting up.

public NotificationCompat.BuildersetColor(int argb)

Sets Notification.

public NotificationCompat.BuildersetColorized(boolean colorize)

Set whether this notification should be colorized.

public NotificationCompat.BuildersetContent(RemoteViews views)

Supply a custom RemoteViews to use instead of the standard one.

public NotificationCompat.BuildersetContentInfo(java.lang.CharSequence info)

A small piece of additional information pertaining to this notification.

public NotificationCompat.BuildersetContentIntent(PendingIntent intent)

Supply a PendingIntent to send when the notification is clicked.

public NotificationCompat.BuildersetContentText(java.lang.CharSequence text)

Set the text (second row) of the notification, in a standard notification.

public NotificationCompat.BuildersetContentTitle(java.lang.CharSequence title)

Set the title (first row) of the notification, in a standard notification.

public NotificationCompat.BuildersetCustomBigContentView(RemoteViews contentView)

Supply custom RemoteViews to use instead of the platform template in the expanded form.

public NotificationCompat.BuildersetCustomContentView(RemoteViews contentView)

Supply custom RemoteViews to use instead of the platform template.

public NotificationCompat.BuildersetCustomHeadsUpContentView(RemoteViews contentView)

Supply custom RemoteViews to use instead of the platform template in the heads up dialog.

public NotificationCompat.BuildersetDefaults(int defaults)

Set the default notification options that will be used.

public NotificationCompat.BuildersetDeleteIntent(PendingIntent intent)

Supply a PendingIntent to send when the notification is cleared by the user directly from the notification panel.

public NotificationCompat.BuildersetExtras(Bundle extras)

Set metadata for this notification.

public NotificationCompat.BuildersetForegroundServiceBehavior(int behavior)

Specify a desired visibility policy for a Notification associated with a foreground service.

public NotificationCompat.BuildersetFullScreenIntent(PendingIntent intent, boolean highPriority)

An intent to launch instead of posting the notification to the status bar.

public NotificationCompat.BuildersetGroup(java.lang.String groupKey)

Set this notification to be part of a group of notifications sharing the same key.

public NotificationCompat.BuildersetGroupAlertBehavior(int groupAlertBehavior)

Sets the group alert behavior for this notification.

public NotificationCompat.BuildersetGroupSummary(boolean isGroupSummary)

Set this notification to be the group summary for a group of notifications.

public NotificationCompat.BuildersetLargeIcon(Bitmap icon)

Set the large icon that is shown in the notification.

public NotificationCompat.BuildersetLights(int argb, int onMs, int offMs)

Set the argb value that you would like the LED on the device to blink, as well as the rate.

public NotificationCompat.BuildersetLocalOnly(boolean b)

Set whether or not this notification is only relevant to the current device.

public NotificationCompat.BuildersetLocusId(LocusIdCompat locusId)

Sets the LocusIdCompat associated with this notification.

public NotificationCompat.BuildersetNotificationSilent()

Silences this instance of the notification, regardless of the sounds or vibrations set on the notification or notification channel.

public NotificationCompat.BuildersetNumber(int number)

Sets the number of items this notification represents.

public NotificationCompat.BuildersetOngoing(boolean ongoing)

Set whether this is an ongoing notification.

public NotificationCompat.BuildersetOnlyAlertOnce(boolean onlyAlertOnce)

Set this flag if you would only like the sound, vibrate and ticker to be played if the notification is not already showing.

public NotificationCompat.BuildersetPriority(int pri)

Set the relative priority for this notification.

public NotificationCompat.BuildersetProgress(int max, int progress, boolean indeterminate)

Set the progress this notification represents, which may be represented as a .

public NotificationCompat.BuildersetPublicVersion(Notification n)

Supply a replacement Notification whose contents should be shown in insecure contexts (i.e.

public NotificationCompat.BuildersetRemoteInputHistory(java.lang.CharSequence text[])

Set the remote input history.

public NotificationCompat.BuildersetSettingsText(java.lang.CharSequence text)

Provides text that will appear as a link to your application's settings.

public NotificationCompat.BuildersetShortcutId(java.lang.String shortcutId)

From Android 11, messaging notifications (those that use NotificationCompat.MessagingStyle) that use this method to link to a published long-lived sharing shortcut may appear in a dedicated Conversation section of the shade and may show configuration options that are unique to conversations.

public NotificationCompat.BuildersetShortcutInfo(ShortcutInfoCompat shortcutInfo)

Populates this notification with given ShortcutInfoCompat.

public NotificationCompat.BuildersetShowWhen(boolean show)

Control whether the timestamp set with setWhen is shown in the content view.

public NotificationCompat.BuildersetSilent(boolean silent)

If true, silences this instance of the notification, regardless of the sounds or vibrations set on the notification or notification channel.

public NotificationCompat.BuildersetSmallIcon(IconCompat icon)

Set the small icon to use in the notification layouts.

public NotificationCompat.BuildersetSmallIcon(int icon)

Set the small icon to use in the notification layouts.

public NotificationCompat.BuildersetSmallIcon(int icon, int level)

A variant of setSmallIcon(int) that takes an additional level parameter for when the icon is a .

public NotificationCompat.BuildersetSortKey(java.lang.String sortKey)

Set a sort key that orders this notification among other notifications from the same package.

public NotificationCompat.BuildersetSound(Uri sound)

Set the sound to play.

public NotificationCompat.BuildersetSound(Uri sound, int streamType)

Set the sound to play.

public NotificationCompat.BuildersetStyle(NotificationCompat.Style style)

Add a rich notification style to be applied at build time.

public NotificationCompat.BuildersetSubText(java.lang.CharSequence text)

This provides some additional information that is displayed in the notification.

public NotificationCompat.BuildersetTicker(java.lang.CharSequence tickerText)

Sets the "ticker" text which is sent to accessibility services.

public NotificationCompat.BuildersetTicker(java.lang.CharSequence tickerText, RemoteViews views)

Sets the "ticker" text which is sent to accessibility services.

public NotificationCompat.BuildersetTimeoutAfter(long durationMs)

Specifies the time at which this notification should be canceled, if it is not already canceled.

public NotificationCompat.BuildersetUsesChronometer(boolean b)

Show the Notification field as a stopwatch.

public NotificationCompat.BuildersetVibrate(long[] pattern[])

Set the vibration pattern to use.

public NotificationCompat.BuildersetVisibility(int visibility)

Sets Notification.

public NotificationCompat.BuildersetWhen(long when)

Set the time that the event occurred.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Fields

public Context mContext

public java.util.ArrayList<NotificationCompat.Action> mActions

public java.util.ArrayList<Person> mPersonList

public java.util.ArrayList<java.lang.String> mPeople

Deprecated: This field was not meant to be public.

Constructors

public Builder(Context context, Notification notification)

Creates a NotificationCompat.Builder which can be used to build a notification that is equivalent to the given one, such that updates can be made to an existing notification with the NotitifactionCompat.Builder API.

public Builder(Context context, java.lang.String channelId)

Constructor. Automatically sets the when field to System.currentTimeMillis() and the audio stream to the Notification.

Parameters:

context: A that will be used to construct the RemoteViews. The Context will not be held past the lifetime of this Builder object.
channelId: The constructed Notification will be posted on this NotificationChannel.

public Builder(Context context)

Deprecated: use Builder(Context, String) instead. All posted notifications must specify a NotificationChannel ID.

Methods

public NotificationCompat.Builder setWhen(long when)

Set the time that the event occurred. Notifications in the panel are sorted by this time.

For apps targeting and above, this time is not shown anymore by default and must be opted into using NotificationCompat.Builder.setShowWhen(boolean)

public NotificationCompat.Builder setShowWhen(boolean show)

Control whether the timestamp set with setWhen is shown in the content view.

For apps targeting and above, this defaults to false. For earlier apps, the default is true.

public NotificationCompat.Builder setSmallIcon(IconCompat icon)

Set the small icon to use in the notification layouts. Different classes of devices may return different sizes. See the UX guidelines for more information on how to design these icons.

Parameters:

icon: The small Icon object to use

public NotificationCompat.Builder setUsesChronometer(boolean b)

Show the Notification field as a stopwatch. Instead of presenting when as a timestamp, the notification will show an automatically updating display of the minutes and seconds since when. Useful when showing an elapsed time (like an ongoing phone call).

See also: , Notification

public NotificationCompat.Builder setChronometerCountDown(boolean countsDown)

Sets the Chronometer to count down instead of counting up. This is only relevant if setUsesChronometer(boolean) has been set to true. If it isn't set the chronometer will count up.

See also:

public NotificationCompat.Builder setSmallIcon(int icon)

Set the small icon to use in the notification layouts. Different classes of devices may return different sizes. See the UX guidelines for more information on how to design these icons.

Parameters:

icon: A resource ID in the application's package of the drawable to use.

public NotificationCompat.Builder setSmallIcon(int icon, int level)

A variant of setSmallIcon(int) that takes an additional level parameter for when the icon is a .

Parameters:

icon: A resource ID in the application's package of the drawable to use.
level: The level to use for the icon.

See also:

public NotificationCompat.Builder setNotificationSilent()

Deprecated: use NotificationCompat.Builder.setSilent(boolean)

Silences this instance of the notification, regardless of the sounds or vibrations set on the notification or notification channel.

public NotificationCompat.Builder setSilent(boolean silent)

If true, silences this instance of the notification, regardless of the sounds or vibrations set on the notification or notification channel. If false, then the normal sound and vibration logic applies. Defaults to false.

public NotificationCompat.Builder setContentTitle(java.lang.CharSequence title)

Set the title (first row) of the notification, in a standard notification.

public NotificationCompat.Builder setContentText(java.lang.CharSequence text)

Set the text (second row) of the notification, in a standard notification.

public NotificationCompat.Builder setSubText(java.lang.CharSequence text)

This provides some additional information that is displayed in the notification. No guarantees are given where exactly it is displayed.

This information should only be provided if it provides an essential benefit to the understanding of the notification. The more text you provide the less readable it becomes. For example, an email client should only provide the account name here if more than one email account has been added.

As of this information is displayed in the notification header area.

On Android versions before this will be shown in the third line of text in the platform notification template. You should not be using NotificationCompat.Builder.setProgress(int, int, boolean) at the same time on those versions; they occupy the same place.

public NotificationCompat.Builder setSettingsText(java.lang.CharSequence text)

Provides text that will appear as a link to your application's settings.

This text does not appear within notification templates but may appear when the user uses an affordance to learn more about the notification. Additionally, this text will not appear unless you provide a valid link target by handling NotificationCompat.INTENT_CATEGORY_NOTIFICATION_PREFERENCES.

This text is meant to be concise description about what the user can customize when they click on this link. The recommended maximum length is 40 characters.

Prior to this field has no effect.

public NotificationCompat.Builder setRemoteInputHistory(java.lang.CharSequence text[])

Set the remote input history. This should be set to the most recent inputs that have been sent through a RemoteInput of this Notification and cleared once the it is no longer relevant (e.g. for chat notifications once the other party has responded). The most recent input must be stored at the 0 index, the second most recent at the 1 index, etc. Note that the system will limit both how far back the inputs will be shown and how much of each individual input is shown.

Note: The reply text will only be shown on notifications that have least one action with a RemoteInput.

public NotificationCompat.Builder setNumber(int number)

Sets the number of items this notification represents. On the latest platforms, this may be displayed as a badge count for Launchers that support badging. Prior to it could be shown in the header. And prior to this was shown in the notification on the right side.

public NotificationCompat.Builder setContentInfo(java.lang.CharSequence info)

A small piece of additional information pertaining to this notification. Where this text is displayed varies between platform versions. Use NotificationCompat.Builder.setSubText(CharSequence) instead to set a text in the header. For legacy apps targeting a version below this field will still show up, but the subtext will take precedence.

public NotificationCompat.Builder setProgress(int max, int progress, boolean indeterminate)

Set the progress this notification represents, which may be represented as a .

public NotificationCompat.Builder setContent(RemoteViews views)

Supply a custom RemoteViews to use instead of the standard one.

public NotificationCompat.Builder setContentIntent(PendingIntent intent)

Supply a PendingIntent to send when the notification is clicked. If you do not supply an intent, you can now add PendingIntents to individual views to be launched when clicked by calling . Be sure to read Notification.contentIntent for how to correctly use this.

public NotificationCompat.Builder setDeleteIntent(PendingIntent intent)

Supply a PendingIntent to send when the notification is cleared by the user directly from the notification panel. For example, this intent is sent when the user clicks the "Clear all" button, or the individual "X" buttons on notifications. This intent is not sent when the application calls .

public NotificationCompat.Builder setFullScreenIntent(PendingIntent intent, boolean highPriority)

An intent to launch instead of posting the notification to the status bar. Only for use with extremely high-priority notifications demanding the user's immediate attention, such as an incoming phone call or alarm clock that the user has explicitly set to a particular time. If this facility is used for something else, please give the user an option to turn it off and use a normal notification, as this can be extremely disruptive.

On some platforms, the system UI may choose to display a heads-up notification, instead of launching this intent, while the user is using the device.

Parameters:

intent: The pending intent to launch.
highPriority: Passing true will cause this notification to be sent even if other notifications are suppressed.

public NotificationCompat.Builder setTicker(java.lang.CharSequence tickerText)

Sets the "ticker" text which is sent to accessibility services. Prior to , sets the text that is displayed in the status bar when the notification first arrives.

public NotificationCompat.Builder setTicker(java.lang.CharSequence tickerText, RemoteViews views)

Deprecated: use NotificationCompat.Builder.setTicker(CharSequence)

Sets the "ticker" text which is sent to accessibility services. Prior to , sets the text that is displayed in the status bar when the notification first arrives, and also a RemoteViews object that may be displayed instead on some devices.

public NotificationCompat.Builder setLargeIcon(Bitmap icon)

Set the large icon that is shown in the notification.

public NotificationCompat.Builder setSound(Uri sound)

Set the sound to play. It will play on the default stream.

On some platforms, a notification that is noisy is more likely to be presented as a heads-up notification.

On platforms and above this value is ignored in favor of the value set on the notification's channel. On older platforms, this value is still used, so it is still required for apps supporting those platforms.

See also: NotificationChannelCompat.Builder.setSound(Uri, AudioAttributes)

public NotificationCompat.Builder setSound(Uri sound, int streamType)

Set the sound to play. It will play on the stream you supply.

On some platforms, a notification that is noisy is more likely to be presented as a heads-up notification.

On platforms and above this value is ignored in favor of the value set on the notification's channel. On older platforms, this value is still used, so it is still required for apps supporting those platforms.

See also: NotificationChannelCompat.Builder.setSound(Uri, AudioAttributes), Notification, for the STREAM_ constants.

public NotificationCompat.Builder setVibrate(long[] pattern[])

Set the vibration pattern to use.

On some platforms, a notification that vibrates is more likely to be presented as a heads-up notification.

On platforms and above this value is ignored in favor of the value set on the notification's channel. On older platforms, this value is still used, so it is still required for apps supporting those platforms.

See also: NotificationChannelCompat.Builder.setVibrationEnabled(boolean), NotificationChannelCompat.Builder.setVibrationPattern(long[])

public NotificationCompat.Builder setLights(int argb, int onMs, int offMs)

Set the argb value that you would like the LED on the device to blink, as well as the rate. The rate is specified in terms of the number of milliseconds to be on and then the number of milliseconds to be off.

On platforms and above this value is ignored in favor of the value set on the notification's channel. On older platforms, this value is still used, so it is still required for apps supporting those platforms.

See also: NotificationChannelCompat.Builder.setLightsEnabled(boolean), NotificationChannelCompat.Builder.setLightColor(int)

public NotificationCompat.Builder setOngoing(boolean ongoing)

Set whether this is an ongoing notification. Ongoing notifications cannot be dismissed by the user, so your application or service must take care of canceling them. They are typically used to indicate a background task that the user is actively engaged with (e.g., playing music) or is pending in some way and therefore occupying the device (e.g., a file download, sync operation, active network connection).

See also: Notification

public NotificationCompat.Builder setColorized(boolean colorize)

Set whether this notification should be colorized. When set, the color set with NotificationCompat.Builder.setColor(int) will be used as the background color of this notification.

This should only be used for high priority ongoing tasks like navigation, an ongoing call, or other similarly high-priority events for the user.

For most styles, the coloring will only be applied if the notification is for a foreground service notification.

However, for MediaStyle and DecoratedMediaCustomViewStyle notifications that have a media session attached there is no such requirement.

Calling this method on any version prior to will not have an effect on the notification and it won't be colorized.

See also: NotificationCompat.Builder.setColor(int)

public NotificationCompat.Builder setOnlyAlertOnce(boolean onlyAlertOnce)

Set this flag if you would only like the sound, vibrate and ticker to be played if the notification is not already showing.

public NotificationCompat.Builder setAutoCancel(boolean autoCancel)

Setting this flag will make it so the notification is automatically canceled when the user clicks it in the panel.

public NotificationCompat.Builder setLocalOnly(boolean b)

Set whether or not this notification is only relevant to the current device.

Some notifications can be bridged to other devices for remote display. This hint can be set to recommend this notification not be bridged.

public NotificationCompat.Builder setCategory(java.lang.String category)

Set the notification category.

Must be one of the predefined notification categories (see the CATEGORY_* constants in Notification) that best describes this notification. May be used by the system for ranking and filtering.

public NotificationCompat.Builder setDefaults(int defaults)

Set the default notification options that will be used.

The value should be one or more of the following fields combined with bitwise-or: Notification, Notification, Notification.

For all default values, use Notification.

On platforms and above this value is ignored in favor of the values set on the notification's channel. On older platforms, this value is still used, so it is still required for apps supporting those platforms.

See also: NotificationChannelCompat.Builder.setVibrationEnabled(boolean), NotificationChannelCompat.Builder.setLightsEnabled(boolean)

public NotificationCompat.Builder setPriority(int pri)

Set the relative priority for this notification.

Priority is an indication of how much of the user's valuable attention should be consumed by this notification. Low-priority notifications may be hidden from the user in certain situations, while the user might be interrupted for a higher-priority notification. The system sets a notification's priority based on various factors including the setPriority value. The effect may differ slightly on different platforms.

On platforms and above this value is ignored in favor of the importance value set on the notification's channel. On older platforms, this value is still used, so it is still required for apps supporting those platforms.

Parameters:

pri: Relative priority for this notification. Must be one of the priority constants defined by NotificationCompat. Acceptable values range from NotificationCompat.PRIORITY_MIN (-2) to NotificationCompat.PRIORITY_MAX (2).

See also: NotificationChannelCompat.Builder.setImportance(int)

public NotificationCompat.Builder addPerson(java.lang.String uri)

Deprecated: use NotificationCompat.Builder.addPerson(Person)

Add a person that is relevant to this notification.

Depending on user preferences, this annotation may allow the notification to pass through interruption filters, and to appear more prominently in the user interface.

The person should be specified by the String representation of a .

The system will also attempt to resolve mailto: and tel: schema URIs. The path part of these URIs must exist in the contacts database, in the appropriate column, or the reference will be discarded as invalid. Telephone schema URIs will be resolved by .

Parameters:

uri: A URI for the person.

See also: Notification

public NotificationCompat.Builder addPerson(Person person)

Add a person that is relevant to this notification.

Depending on user preferences, this annotation may allow the notification to pass through interruption filters, if this notification is of category NotificationCompat.CATEGORY_CALL or NotificationCompat.CATEGORY_MESSAGE. The addition of people may also cause this notification to appear more prominently in the user interface.

A person should usually contain a uri in order to benefit from the ranking boost. However, even if no uri is provided, it's beneficial to provide other people in the notification, such that listeners and voice only devices can announce and handle them properly.

Parameters:

person: the person to add.

See also: NotificationCompat.EXTRA_PEOPLE_LIST

public NotificationCompat.Builder clearPeople()

Clear any people added via either NotificationCompat.Builder.addPerson(Person) or NotificationCompat.Builder.addPerson(String)

public NotificationCompat.Builder setGroup(java.lang.String groupKey)

Set this notification to be part of a group of notifications sharing the same key. Grouped notifications may display in a cluster or stack on devices which support such rendering.

To make this notification the summary for its group, also call NotificationCompat.Builder.setGroupSummary(boolean). A sort order can be specified for group members by using NotificationCompat.Builder.setSortKey(String).

Parameters:

groupKey: The group key of the group.

Returns:

this object for method chaining

public NotificationCompat.Builder setGroupSummary(boolean isGroupSummary)

Set this notification to be the group summary for a group of notifications. Grouped notifications may display in a cluster or stack on devices which support such rendering. Requires a group key also be set using NotificationCompat.Builder.setGroup(String).

Parameters:

isGroupSummary: Whether this notification should be a group summary.

Returns:

this object for method chaining

public NotificationCompat.Builder setSortKey(java.lang.String sortKey)

Set a sort key that orders this notification among other notifications from the same package. This can be useful if an external sort was already applied and an app would like to preserve this. Notifications will be sorted lexicographically using this value, although providing different priorities in addition to providing sort key may cause this value to be ignored.

This sort key can also be used to order members of a notification group. See NotificationCompat.Builder.setGroup(String).

See also: compareTo

public NotificationCompat.Builder addExtras(Bundle extras)

Merge additional metadata into this notification.

Values within the Bundle will replace existing extras values in this Builder.

See also: Notification

public NotificationCompat.Builder setExtras(Bundle extras)

Set metadata for this notification.

A reference to the Bundle is held for the lifetime of this Builder, and the Bundle's current contents are copied into the Notification each time NotificationCompat.Builder.build() is called.

Replaces any existing extras values with those from the provided Bundle. Use NotificationCompat.Builder.addExtras(Bundle) to merge in metadata instead.

See also: Notification

public Bundle getExtras()

Get the current metadata Bundle used by this notification Builder.

The returned Bundle is shared with this Builder.

The current contents of this Bundle are copied into the Notification each time NotificationCompat.Builder.build() is called.

See also: Notification

public NotificationCompat.Builder addAction(int icon, java.lang.CharSequence title, PendingIntent intent)

Add an action to this notification. Actions are typically displayed by the system as a button adjacent to the notification content.
Action buttons won't appear on platforms prior to Android 4.1. Action buttons depend on expanded notifications, which are only available in Android 4.1 and later. To ensure that an action button's functionality is always available, first implement the functionality in the that starts when a user clicks the notification (see setContentIntent()), and then enhance the notification by implementing the same functionality with addAction().

Parameters:

icon: Resource ID of a drawable that represents the action.
title: Text describing the action.
intent: android.app.PendingIntent to be fired when the action is invoked.

Add an action to this notification. Actions are typically displayed by the system as a button adjacent to the notification content.
Action buttons won't appear on platforms prior to Android 4.1. Action buttons depend on expanded notifications, which are only available in Android 4.1 and later. To ensure that an action button's functionality is always available, first implement the functionality in the that starts when a user clicks the notification (see setContentIntent()), and then enhance the notification by implementing the same functionality with addAction().

Parameters:

action: The action to add.

public NotificationCompat.Builder clearActions()

Clear any actions added via NotificationCompat.Builder.addAction(int, CharSequence, PendingIntent)

public NotificationCompat.Builder addInvisibleAction(int icon, java.lang.CharSequence title, PendingIntent intent)

Add an invisible action to this notification. Invisible actions are never displayed by the system, but can be retrieved and used by other application listening to system notifications. Invisible actions are supported from Android 4.4.4 (API 20) and can be retrieved using NotificationCompat.getInvisibleActions(Notification).

Parameters:

icon: Resource ID of a drawable that represents the action.
title: Text describing the action.
intent: android.app.PendingIntent to be fired when the action is invoked.

public NotificationCompat.Builder addInvisibleAction(NotificationCompat.Action action)

Add an invisible action to this notification. Invisible actions are never displayed by the system, but can be retrieved and used by other application listening to system notifications. Invisible actions are supported from Android 4.4.4 (API 20) and can be retrieved using NotificationCompat.getInvisibleActions(Notification).

Parameters:

action: The action to add.

public NotificationCompat.Builder clearInvisibleActions()

Clear any invisible actions added via NotificationCompat.Builder.addInvisibleAction(int, CharSequence, PendingIntent)

Add a rich notification style to be applied at build time.
If the platform does not provide rich notification styles, this method has no effect. The user will always see the normal notification style.

Parameters:

style: Object responsible for modifying the notification style.

public NotificationCompat.Builder setColor(int argb)

Sets Notification.

Parameters:

argb: The accent color to use

Returns:

The same Builder.

public NotificationCompat.Builder setVisibility(int visibility)

Sets Notification.

Parameters:

visibility: One of Notification (the default), Notification, or Notification.

public NotificationCompat.Builder setPublicVersion(Notification n)

Supply a replacement Notification whose contents should be shown in insecure contexts (i.e. atop the secure lockscreen). See Notification and NotificationCompat.VISIBILITY_PUBLIC.

Parameters:

n: A replacement notification, presumably with some or all info redacted.

Returns:

The same Builder.

public RemoteViews createContentView()

Construct a RemoteViews for the final notification layout.

public RemoteViews createBigContentView()

Construct a RemoteViews for the final big notification layout.

public RemoteViews createHeadsUpContentView()

Construct a RemoteViews for the final heads-up notification layout.

public NotificationCompat.Builder setCustomContentView(RemoteViews contentView)

Supply custom RemoteViews to use instead of the platform template. This will override the layout that would otherwise be constructed by this Builder object.

public NotificationCompat.Builder setCustomBigContentView(RemoteViews contentView)

Supply custom RemoteViews to use instead of the platform template in the expanded form. This will override the expanded layout that would otherwise be constructed by this Builder object. No-op on versions prior to .

public NotificationCompat.Builder setCustomHeadsUpContentView(RemoteViews contentView)

Supply custom RemoteViews to use instead of the platform template in the heads up dialog. This will override the heads-up layout that would otherwise be constructed by this Builder object. No-op on versions prior to .

public NotificationCompat.Builder setChannelId(java.lang.String channelId)

Specifies the channel the notification should be delivered on. No-op on versions prior to .

public NotificationCompat.Builder setTimeoutAfter(long durationMs)

Specifies the time at which this notification should be canceled, if it is not already canceled. No-op on versions prior to .

public NotificationCompat.Builder setShortcutId(java.lang.String shortcutId)

From Android 11, messaging notifications (those that use NotificationCompat.MessagingStyle) that use this method to link to a published long-lived sharing shortcut may appear in a dedicated Conversation section of the shade and may show configuration options that are unique to conversations. This behavior should be reserved for person to person(s) conversations where there is a likely social obligation for an individual to respond.

For example, the following are some examples of notifications that belong in the conversation space:

  • 1:1 conversations between two individuals
  • Group conversations between individuals where everyone can contribute
And the following are some examples of notifications that do not belong in the conversation space:
  • Advertisements from a bot (even if personal and contextualized)
  • Engagement notifications from a bot
  • Directional conversations where there is an active speaker and many passive individuals
  • Stream / posting updates from other individuals
  • Email, document comments, or other conversation types that are not real-time

Additionally, this method can be used for all types of notifications to mark this notification as duplicative of a Launcher shortcut. Launchers that show badges or notification content may then suppress the shortcut in favor of the content of this notification.

If this notification has NotificationCompat.BubbleMetadata attached that was created with a shortcutId a check will be performed to ensure the shortcutId supplied to bubble metadata matches the shortcutId set here, if one was set. If the shortcutId's were specified but do not match, an exception is thrown.

Parameters:

shortcutId: the id of the shortcut this notification is linked to

See also: NotificationCompat.BubbleMetadata.Builder

public NotificationCompat.Builder setShortcutInfo(ShortcutInfoCompat shortcutInfo)

Populates this notification with given ShortcutInfoCompat.

Sets shortcutId based on the given shortcut. In addition, it also sets locusId and contentTitle if they were empty.

public NotificationCompat.Builder setLocusId(LocusIdCompat locusId)

Sets the LocusIdCompat associated with this notification.

This method should be called when the LocusIdCompat is used in other places (such as ShortcutInfoCompat and ) so the device's intelligence services can correlate them.

public NotificationCompat.Builder setBadgeIconType(int icon)

Sets which icon to display as a badge for this notification.

Must be one of NotificationCompat.BADGE_ICON_NONE, NotificationCompat.BADGE_ICON_SMALL, NotificationCompat.BADGE_ICON_LARGE.

Note: This value might be ignored, for launchers that don't support badge icons.

public NotificationCompat.Builder setGroupAlertBehavior(int groupAlertBehavior)

Sets the group alert behavior for this notification. Use this method to mute this notification if alerts for this notification's group should be handled by a different notification. This is only applicable for notifications that belong to a group. This must be called on all notifications you want to mute. For example, if you want only the summary of your group to make noise, all children in the group should have the group alert behavior NotificationCompat.GROUP_ALERT_SUMMARY.

The default value is NotificationCompat.GROUP_ALERT_ALL.

public NotificationCompat.Builder setForegroundServiceBehavior(int behavior)

Specify a desired visibility policy for a Notification associated with a foreground service. The default value is NotificationCompat.FOREGROUND_SERVICE_DEFAULT, meaning the system can choose to defer visibility of the notification for a short time after the service is started. Pass FOREGROUND_SERVICE_IMMEDIATE to this method in order to guarantee that visibility is never deferred. Pass FOREGROUND_SERVICE_DEFERRED to request that visibility is deferred whenever possible.

Note that deferred visibility is not guaranteed. There may be some circumstances under which the system will show the foreground service's associated Notification immediately even when the app has used this method to explicitly request deferred display.

This method has no effect when running on versions prior to .

Sets the NotificationCompat.BubbleMetadata that will be used to display app content in a floating window over the existing foreground activity.

This data will be ignored unless the notification is posted to a channel that allows .

Notifications allowed to bubble that have valid bubble metadata will display in collapsed state outside of the notification shade on unlocked devices. When a user interacts with the collapsed state, the bubble intent will be invoked and displayed.

Apply an extender to this notification builder. Extenders may be used to add metadata or change options on this builder.

public NotificationCompat.Builder setAllowSystemGeneratedContextualActions(boolean allowed)

Determines whether the platform can generate contextual actions for a notification. By default this is true.

public Notification getNotification()

Deprecated: Use NotificationCompat.Builder.build() instead.

public Notification build()

Combine all of the options that have been set and return a new Notification object.

protected static java.lang.CharSequence limitCharSequenceLength(java.lang.CharSequence cs)

public RemoteViews getContentView()

public RemoteViews getBigContentView()

public RemoteViews getHeadsUpContentView()

public long getWhenIfShowing()

return when if it is showing or 0 otherwise

public int getPriority()

Returns:

the priority set on the notification

public int getForegroundServiceBehavior()

Returns:

the foreground service behavior defined for the notification

public int getColor()

Returns:

the color of the notification

public NotificationCompat.BubbleMetadata getBubbleMetadata()

Returns:

the NotificationCompat.BubbleMetadata of the notification