lightbulb_outline Help shape the future of the Google Play Console, Android Studio, and Firebase. Start survey

belongs to Maven artifact androidx.core:core:1.0.0-alpha3

NotificationCompat.Builder

public static class NotificationCompat.Builder
extends Object

java.lang.Object
   ↳ androidx.core.app.NotificationCompat.Builder


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 Activity in your app, and you should always start that Activity when users click the notification. To do this, use the setContentIntent() method.

Summary

Fields

public ArrayList<String> mPeople

This field is deprecated. This field was not meant to be public.

Public constructors

NotificationCompat.Builder(Context context, String channelId)

Constructor.

NotificationCompat.Builder(Context context)

This constructor is deprecated. use NotificationCompat.Builder(Context, String) instead. All posted Notifications must specify a NotificationChannel Id.

Public methods

NotificationCompat.Builder addAction(NotificationCompat.Action action)

Add an action to this notification.

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

Add an action to this notification.

NotificationCompat.Builder addExtras(Bundle extras)

Merge additional metadata into this notification.

NotificationCompat.Builder addInvisibleAction(NotificationCompat.Action action)

Add an invisible action to this notification.

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

Add an invisible action to this notification.

NotificationCompat.Builder addPerson(String uri)

Add a person that is relevant to this notification.

Notification build()

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

NotificationCompat.Builder extend(NotificationCompat.Extender extender)

Apply an extender to this notification builder.

Bundle getExtras()

Get the current metadata Bundle used by this notification Builder.

Notification getNotification()

This method is deprecated. Use build() instead.

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.

NotificationCompat.Builder setBadgeIconType(int icon)

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

NotificationCompat.Builder setCategory(String category)

Set the notification category.

NotificationCompat.Builder setChannelId(String channelId)

Specifies the channel the notification should be delivered on.

NotificationCompat.Builder setColor(int argb)

Sets Notification.color.

NotificationCompat.Builder setColorized(boolean colorize)

Set whether this notification should be colorized.

NotificationCompat.Builder setContent(RemoteViews views)

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

NotificationCompat.Builder setContentInfo(CharSequence info)

Set the large text at the right-hand side of the notification.

NotificationCompat.Builder setContentIntent(PendingIntent intent)

Supply a PendingIntent to send when the notification is clicked.

NotificationCompat.Builder setContentText(CharSequence text)

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

NotificationCompat.Builder setContentTitle(CharSequence title)

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

NotificationCompat.Builder setCustomBigContentView(RemoteViews contentView)

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

NotificationCompat.Builder setCustomContentView(RemoteViews contentView)

Supply custom RemoteViews to use instead of the platform template.

NotificationCompat.Builder setCustomHeadsUpContentView(RemoteViews contentView)

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

NotificationCompat.Builder setDefaults(int defaults)

Set the default notification options that will be used.

NotificationCompat.Builder setDeleteIntent(PendingIntent intent)

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

NotificationCompat.Builder setExtras(Bundle extras)

Set metadata for this notification.

NotificationCompat.Builder setFullScreenIntent(PendingIntent intent, boolean highPriority)

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

NotificationCompat.Builder setGroup(String groupKey)

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

NotificationCompat.Builder setGroupAlertBehavior(int groupAlertBehavior)

Sets the group alert behavior for this notification.

NotificationCompat.Builder setGroupSummary(boolean isGroupSummary)

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

NotificationCompat.Builder setLargeIcon(Bitmap icon)

Set the large icon that is shown in the ticker and notification.

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.

NotificationCompat.Builder setLocalOnly(boolean b)

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

NotificationCompat.Builder setNumber(int number)

Set the large number at the right-hand side of the notification.

NotificationCompat.Builder setOngoing(boolean ongoing)

Set whether this is an ongoing notification.

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.

NotificationCompat.Builder setPriority(int pri)

Set the relative priority for this notification.

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

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

NotificationCompat.Builder setPublicVersion(Notification n)

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

NotificationCompat.Builder setRemoteInputHistory(CharSequence[] text)

Set the remote input history.

NotificationCompat.Builder setShortcutId(String shortcutId)

If this notification is duplicative of a Launcher shortcut, sets the id of the shortcut, in case the Launcher wants to hide the shortcut.

NotificationCompat.Builder setShowWhen(boolean show)

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

NotificationCompat.Builder setSmallIcon(int icon, int level)

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

NotificationCompat.Builder setSmallIcon(int icon)

Set the small icon to use in the notification layouts.

NotificationCompat.Builder setSortKey(String sortKey)

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

NotificationCompat.Builder setSound(Uri sound)

Set the sound to play.

NotificationCompat.Builder setSound(Uri sound, int streamType)

Set the sound to play.

NotificationCompat.Builder setStyle(NotificationCompat.Style style)

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

NotificationCompat.Builder setSubText(CharSequence text)

Set the third line of text in the platform notification template.

NotificationCompat.Builder setTicker(CharSequence tickerText, RemoteViews views)

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

NotificationCompat.Builder setTicker(CharSequence tickerText)

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

NotificationCompat.Builder setTimeoutAfter(long durationMs)

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

NotificationCompat.Builder setUsesChronometer(boolean b)

Show the Notification.when field as a stopwatch.

NotificationCompat.Builder setVibrate(long[] pattern)

Set the vibration pattern to use.

NotificationCompat.Builder setVisibility(int visibility)

Sets Notification.visibility.

NotificationCompat.Builder setWhen(long when)

Set the time that the event occurred.

Protected methods

static CharSequence limitCharSequenceLength(CharSequence cs)

Inherited methods

Fields

mPeople

public ArrayList<String> mPeople

This field is deprecated.
This field was not meant to be public.

Public constructors

NotificationCompat.Builder

public NotificationCompat.Builder (Context context, 
                String channelId)

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

Parameters
context Context: A Context that will be used to construct the RemoteViews. The Context will not be held past the lifetime of this Builder object.

channelId String: The constructed Notification will be posted on this NotificationChannel.

NotificationCompat.Builder

public NotificationCompat.Builder (Context context)

This constructor is deprecated.
use NotificationCompat.Builder(Context, String) instead. All posted Notifications must specify a NotificationChannel Id.

Parameters
context Context

Public methods

addAction

public NotificationCompat.Builder addAction (NotificationCompat.Action action)

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 Activity that starts when a user clicks the notification (see setContentIntent()), and then enhance the notification by implementing the same functionality with addAction().

Parameters
action NotificationCompat.Action: The action to add.

Returns
NotificationCompat.Builder

addAction

public NotificationCompat.Builder addAction (int icon, 
                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 Activity that starts when a user clicks the notification (see setContentIntent()), and then enhance the notification by implementing the same functionality with addAction().

Parameters
icon int: Resource ID of a drawable that represents the action.

title CharSequence: Text describing the action.

intent PendingIntent: PendingIntent to be fired when the action is invoked.

Returns
NotificationCompat.Builder

addExtras

public NotificationCompat.Builder addExtras (Bundle extras)

Merge additional metadata into this notification.

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

Parameters
extras Bundle

Returns
NotificationCompat.Builder

addInvisibleAction

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 NotificationCompat.Action: The action to add.

Returns
NotificationCompat.Builder

addInvisibleAction

public NotificationCompat.Builder addInvisibleAction (int icon, 
                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 int: Resource ID of a drawable that represents the action.

title CharSequence: Text describing the action.

intent PendingIntent: PendingIntent to be fired when the action is invoked.

Returns
NotificationCompat.Builder

addPerson

public NotificationCompat.Builder addPerson (String uri)

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 ContactsContract.Contacts.CONTENT_LOOKUP_URI.

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 ContactsContract.PhoneLookup.

Parameters
uri String: A URI for the person.

Returns
NotificationCompat.Builder

build

public Notification build ()

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

Returns
Notification

extend

public NotificationCompat.Builder extend (NotificationCompat.Extender extender)

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

Parameters
extender NotificationCompat.Extender

Returns
NotificationCompat.Builder

getExtras

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 build() is called.

Returns
Bundle

getNotification

public Notification getNotification ()

This method is deprecated.
Use build() instead.

Returns
Notification

setAutoCancel

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. The PendingIntent set with setDeleteIntent(PendingIntent) will be broadcast when the notification is canceled.

Parameters
autoCancel boolean

Returns
NotificationCompat.Builder

setBadgeIconType

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.

Parameters
icon int

Returns
NotificationCompat.Builder

setCategory

public NotificationCompat.Builder setCategory (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.

Parameters
category String

Returns
NotificationCompat.Builder

setChannelId

public NotificationCompat.Builder setChannelId (String channelId)

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

Parameters
channelId String

Returns
NotificationCompat.Builder

setColor

public NotificationCompat.Builder setColor (int argb)

Sets Notification.color.

Parameters
argb int: The accent color to use

Returns
NotificationCompat.Builder The same Builder.

setColorized

public NotificationCompat.Builder setColorized (boolean colorize)

Set whether this notification should be colorized. When set, the color set with 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 Build.VERSION_CODES.O will not have an effect on the notification and it won't be colorized.

Parameters
colorize boolean

Returns
NotificationCompat.Builder

See also:

setContent

public NotificationCompat.Builder setContent (RemoteViews views)

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

Parameters
views RemoteViews

Returns
NotificationCompat.Builder

setContentInfo

public NotificationCompat.Builder setContentInfo (CharSequence info)

Set the large text at the right-hand side of the notification.

Parameters
info CharSequence

Returns
NotificationCompat.Builder

setContentIntent

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 RemoteViews.setOnClickPendingIntent(int,PendingIntent). Be sure to read Notification.contentIntent for how to correctly use this.

Parameters
intent PendingIntent

Returns
NotificationCompat.Builder

setContentText

public NotificationCompat.Builder setContentText (CharSequence text)

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

Parameters
text CharSequence

Returns
NotificationCompat.Builder

setContentTitle

public NotificationCompat.Builder setContentTitle (CharSequence title)

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

Parameters
title CharSequence

Returns
NotificationCompat.Builder

setCustomBigContentView

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 Build.VERSION_CODES.JELLY_BEAN.

Parameters
contentView RemoteViews

Returns
NotificationCompat.Builder

setCustomContentView

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.

Parameters
contentView RemoteViews

Returns
NotificationCompat.Builder

setCustomHeadsUpContentView

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 Build.VERSION_CODES.LOLLIPOP.

Parameters
contentView RemoteViews

Returns
NotificationCompat.Builder

setDefaults

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.DEFAULT_SOUND, Notification.DEFAULT_VIBRATE, Notification.DEFAULT_LIGHTS.

For all default values, use Notification.DEFAULT_ALL.

Parameters
defaults int

Returns
NotificationCompat.Builder

setDeleteIntent

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 NotificationManager.cancel(int).

Parameters
intent PendingIntent

Returns
NotificationCompat.Builder

setExtras

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 build() is called.

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

Parameters
extras Bundle

Returns
NotificationCompat.Builder

setFullScreenIntent

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 PendingIntent: The pending intent to launch.

highPriority boolean: Passing true will cause this notification to be sent even if other notifications are suppressed.

Returns
NotificationCompat.Builder

setGroup

public NotificationCompat.Builder setGroup (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 setGroupSummary(boolean). A sort order can be specified for group members by using setSortKey(String).

Parameters
groupKey String: The group key of the group.

Returns
NotificationCompat.Builder this object for method chaining

setGroupAlertBehavior

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.

Parameters
groupAlertBehavior int

Returns
NotificationCompat.Builder

setGroupSummary

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 setGroup(String).

Parameters
isGroupSummary boolean: Whether this notification should be a group summary.

Returns
NotificationCompat.Builder this object for method chaining

setLargeIcon

public NotificationCompat.Builder setLargeIcon (Bitmap icon)

Set the large icon that is shown in the ticker and notification.

Parameters
icon Bitmap

Returns
NotificationCompat.Builder

setLights

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.

Parameters
argb int

onMs int

offMs int

Returns
NotificationCompat.Builder

setLocalOnly

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.

Parameters
b boolean

Returns
NotificationCompat.Builder

setNumber

public NotificationCompat.Builder setNumber (int number)

Set the large number at the right-hand side of the notification. This is equivalent to setContentInfo, although it might show the number in a different font size for readability.

Parameters
number int

Returns
NotificationCompat.Builder

setOngoing

public NotificationCompat.Builder setOngoing (boolean ongoing)

Set whether this is an ongoing notification.

Ongoing notifications differ from regular notifications in the following ways:

  • Ongoing notifications are sorted above the regular notifications in the notification panel.
  • Ongoing notifications do not have an 'X' close button, and are not affected by the "Clear all" button.

Parameters
ongoing boolean

Returns
NotificationCompat.Builder

setOnlyAlertOnce

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.

Parameters
onlyAlertOnce boolean

Returns
NotificationCompat.Builder

setPriority

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.

Parameters
pri int: 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).

Returns
NotificationCompat.Builder

setProgress

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

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

Parameters
max int

progress int

indeterminate boolean

Returns
NotificationCompat.Builder

setPublicVersion

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.visibility and NotificationCompat.VISIBILITY_PUBLIC.

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

Returns
NotificationCompat.Builder The same Builder.

setRemoteInputHistory

public NotificationCompat.Builder setRemoteInputHistory (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.

Parameters
text CharSequence

Returns
NotificationCompat.Builder

setShortcutId

public NotificationCompat.Builder setShortcutId (String shortcutId)

If this notification is duplicative of a Launcher shortcut, sets the id of the shortcut, in case the Launcher wants to hide the shortcut.

Note:This field will be ignored by Launchers that don't support badging or shortcuts.

Parameters
shortcutId String: the id of the shortcut this notification supersedes

Returns
NotificationCompat.Builder

setShowWhen

public NotificationCompat.Builder setShowWhen (boolean show)

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

Parameters
show boolean

Returns
NotificationCompat.Builder

setSmallIcon

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 LevelListDrawable.

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

level int: The level to use for the icon.

Returns
NotificationCompat.Builder

See also:

setSmallIcon

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 int: A resource ID in the application's package of the drawable to use.

Returns
NotificationCompat.Builder

setSortKey

public NotificationCompat.Builder setSortKey (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 setGroup(String).

Parameters
sortKey String

Returns
NotificationCompat.Builder

setSound

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.

Parameters
sound Uri

Returns
NotificationCompat.Builder

setSound

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.

Parameters
sound Uri

streamType int

Returns
NotificationCompat.Builder

setStyle

public NotificationCompat.Builder setStyle (NotificationCompat.Style style)

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 NotificationCompat.Style: Object responsible for modifying the notification style.

Returns
NotificationCompat.Builder

setSubText

public NotificationCompat.Builder setSubText (CharSequence text)

Set the third line of text in the platform notification template. Don't use if you're also using setProgress(int, int, boolean); they occupy the same location in the standard template.
If the platform does not provide large-format notifications, this method has no effect. The third line of text only appears in expanded view.

Parameters
text CharSequence

Returns
NotificationCompat.Builder

setTicker

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

Sets the "ticker" text which is sent to accessibility services. Prior to Build.VERSION_CODES.LOLLIPOP, 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.

Parameters
tickerText CharSequence

views RemoteViews

Returns
NotificationCompat.Builder

setTicker

public NotificationCompat.Builder setTicker (CharSequence tickerText)

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

Parameters
tickerText CharSequence

Returns
NotificationCompat.Builder

setTimeoutAfter

public NotificationCompat.Builder setTimeoutAfter (long durationMs)

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

Parameters
durationMs long

Returns
NotificationCompat.Builder

setUsesChronometer

public NotificationCompat.Builder setUsesChronometer (boolean b)

Show the Notification.when 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).

Parameters
b boolean

Returns
NotificationCompat.Builder

setVibrate

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.

Parameters
pattern long

Returns
NotificationCompat.Builder

setVisibility

public NotificationCompat.Builder setVisibility (int visibility)

Sets Notification.visibility.

Parameters
visibility int: One of Notification.VISIBILITY_PRIVATE (the default), Notification.VISIBILITY_PUBLIC, or Notification.VISIBILITY_SECRET.

Returns
NotificationCompat.Builder

setWhen

public NotificationCompat.Builder setWhen (long when)

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

Parameters
when long

Returns
NotificationCompat.Builder

Protected methods

limitCharSequenceLength

protected static CharSequence limitCharSequenceLength (CharSequence cs)

Parameters
cs CharSequence

Returns
CharSequence