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.