added in version 22.1.0
belongs to Maven artifact


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 was deprecated in API level 27.1.0. This field was not meant to be public.

Public constructors

NotificationCompat.Builder(Context context, String channelId)


NotificationCompat.Builder(Context context)

This constructor was deprecated in API level 26.1.0. 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 was deprecated in API level 22.1.0. 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 color.