public static class NotificationCompat.Builder
extends Object


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.



public ArrayList<String> mPeople

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

Public constructors

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.

Builder(Context context, String channelId)


Builder(Context context)

This constructor is deprecated. use 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)

This method is deprecated. use addPerson(Person)

NotificationCompat.Builder addPerson(Person person)

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 clearActions()

Clear any actions added via addAction(NotificationCompat.Action)

NotificationCompat.Builder clearInvisibleActions()

Clear any invisible actions added via addInvisibleAction(NotificationCompat.Action)

NotificationCompat.Builder clearPeople()

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

RemoteViews createBigContentView()

Construct a RemoteViews for the final big notification layout.

RemoteViews createContentView()

Construct a RemoteViews for the final notification layout.

RemoteViews createHeadsUpContentView()

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

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 setAllowSystemGeneratedContextualActions(boolean allowed)

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

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 setBubbleMetadata(NotificationCompat.BubbleMetadata data)

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

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 setChronometerCountDown(boolean countsDown)

Sets the Chronometer to count down instead of counting up.

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)

A small piece of additional information pertaining to this 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 setForegroundServiceBehavior(int behavior)

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

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 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 setLocusId(LocusIdCompat locusId)

Sets the LocusIdCompat associated with this notification.

NotificationCompat.Builder setNotificationSilent()

This method is deprecated. use setSilent(boolean)

NotificationCompat.Builder setNumber(int number)

Sets the number of items this notification represents.

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 setSettingsText(CharSequence text)

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

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

NotificationCompat.Builder setShortcutInfo(ShortcutInfoCompat shortcutInfo)

Populates this notification with given ShortcutInfoCompat.

NotificationCompat.Builder setShowWhen(boolean show)

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

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.

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(IconCompat icon)

Set the small icon to use in the notification layouts.

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)

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

NotificationCompat.Builder setTicker(CharSequence tickerText, RemoteViews views)

This method is deprecated. use setTicker(CharSequence)

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)