Added in API level 11

Builder

open class Builder
kotlin.Any
   ↳ android.app.Notification.Builder

Builder class for Notification objects. Provides a convenient way to set the various fields of a Notification and generate content views using the platform's notification layout template. If your app supports versions of Android as old as API level 4, you can instead use androidx.core.app.NotificationCompat.Builder, available in the Android Support library.

Example:

Notification noti = new Notification.Builder(mContext)
          .setContentTitle("New mail from " + sender.toString())
          .setContentText(subject)
          .setSmallIcon(R.drawable.new_mail)
          .setLargeIcon(aBitmap)
          .build();
  

Summary

Public constructors
Builder(context: Context!, channelId: String!)

Constructs a new Builder with the defaults:

Builder(context: Context!)

Public methods
open Notification.Builder!
addAction(icon: Int, title: CharSequence!, intent: PendingIntent!)

Add an action to this notification.

open Notification.Builder

Add an action to this notification.

open Notification.Builder
addExtras(extras: Bundle!)

Merge additional metadata into this notification.

open Notification.Builder!

Add a person that is relevant to this notification.

open Notification.Builder
addPerson(person: Person!)

Add a person that is relevant to this notification.

open Notification

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

open RemoteViews!

Construct a RemoteViews for the final big notification layout.

open RemoteViews!

Construct a RemoteViews for the final 1U notification layout.

open RemoteViews!

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

open Notification.Builder

Apply an extender to this notification builder.

open Bundle!

Get the current metadata Bundle used by this notification Builder.

open Notification!

open Notification.Style!

Returns the style set by setStyle(android.app.Notification.Style).

open static Notification.Builder

Creates a Builder from an existing notification so further changes can be made.

open Notification.Builder
setActions(vararg actions: Notification.Action!)

Alter the complete list of actions attached to this notification.

open Notification.Builder

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

open Notification.Builder
setAutoCancel(autoCancel: Boolean)

Make this notification automatically dismissed when the user touches it.

open Notification.Builder

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

open Notification.Builder

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

open Notification.Builder
setCategory(category: String!)

Set the notification category.

open Notification.Builder
setChannelId(channelId: String!)

Specifies the channel the notification should be delivered on.

open Notification.Builder

Sets the Chronometer to count down instead of counting up.

open Notification.Builder
setColor(argb: Int)

Sets Notification#color.

open Notification.Builder
setColorized(colorize: Boolean)

Set whether this notification should be colorized.

open Notification.Builder!

Supply a custom RemoteViews to use instead of the platform template.

open Notification.Builder!

A small piece of additional information pertaining to this notification.

open Notification.Builder

Supply a PendingIntent to be sent when the notification is clicked.

open Notification.Builder

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

open Notification.Builder

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

open Notification.Builder

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

open Notification.Builder

Supply custom RemoteViews to use instead of the platform template.

open Notification.Builder

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

open Notification.Builder!
setDefaults(defaults: Int)

Set which notification properties will be inherited from system defaults.

open Notification.Builder

Supply a PendingIntent to send when the notification is cleared explicitly by the user.

open Notification.Builder
setExtras(extras: Bundle!)

Set metadata for this notification.

open Notification.Builder
setFlag(mask: Int, value: Boolean)

Set the value for a notification flag

open Notification.Builder

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

open Notification.Builder
setFullScreenIntent(intent: PendingIntent!, highPriority: Boolean)

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

open Notification.Builder
setGroup(groupKey: String!)

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

open Notification.Builder
setGroupAlertBehavior(groupAlertBehavior: Int)

Sets the group alert behavior for this notification.

open Notification.Builder
setGroupSummary(isGroupSummary: Boolean)

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

open Notification.Builder

Add a large icon to the notification content view.

open Notification.Builder

Add a large icon to the notification content view.

open Notification.Builder!
setLights(argb: Int, onMs: Int, offMs: Int)

Set the desired color for the indicator LED on the device, as well as the blink duty cycle (specified in milliseconds).

open Notification.Builder
setLocalOnly(localOnly: Boolean)

Set whether or not this notification should not bridge to other devices.

open Notification.Builder
setLocusId(locusId: LocusId?)

Sets the LocusId associated with this notification.

open Notification.Builder
setNumber(number: Int)

Sets the number of items this notification represents.

open Notification.Builder
setOngoing(ongoing: Boolean)

Set whether this is an "ongoing" notification.

open Notification.Builder
setOnlyAlertOnce(onlyAlertOnce: Boolean)

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

open Notification.Builder!

Set the priority of this notification.

open Notification.Builder
setProgress(max: Int, progress: Int, indeterminate: Boolean)

Set the progress this notification represents.

open Notification.Builder

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

open Notification.Builder

Set the remote input history.

open Notification.Builder

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

open Notification.Builder
setShortcutId(shortcutId: String!)

From Android 11, messaging notifications (those that use 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.

open Notification.Builder

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

open Notification.Builder

Set the small icon resource, which will be used to represent the notification in the status bar.

open Notification.Builder
setSmallIcon(icon: Int, level: Int)

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

open Notification.Builder

Set the small icon, which will be used to represent the notification in the status bar and content view (unless overridden there by a large icon).

open Notification.Builder
setSortKey(sortKey: String!)

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

open Notification.Builder!
setSound(sound: Uri!)

Set the sound to play.

open Notification.Builder!
setSound(sound: Uri!, streamType: Int)

Set the sound to play, along with a specific stream on which to play it.

open Notification.Builder!
setSound(sound: Uri!, audioAttributes: AudioAttributes!)

Set the sound to play, along with specific audio attributes to use during playback.

open Notification.Builder

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

open Notification.Builder

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

open Notification.Builder
setTicker(tickerText: CharSequence!)

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

open Notification.Builder!
setTicker(tickerText: CharSequence!, views: RemoteViews!)

Obsolete version of setTicker(java.lang.CharSequence).

open Notification.Builder
setTimeoutAfter(durationMs: Long)

Specifies a duration in milliseconds after which this notification should be canceled, if it is not already canceled.

open Notification.Builder

Show the Notification#when field as a stopwatch.

open Notification.Builder!
setVibrate(pattern: LongArray!)

Set the vibration pattern to use.

open Notification.Builder
setVisibility(visibility: Int)

Specify the value of visibility.

open Notification.Builder
setWhen(when: Long)

Add a timestamp pertaining to the notification (usually the time the event occurred).

Public constructors

Builder

Added in API level 11
Builder(
    context: Context!,
    channelId: String!)

Constructs a new Builder with the defaults:

Parameters
context Context!: A Context that will be used by the Builder 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. To use a NotificationChannel, it must first be created using NotificationManager#createNotificationChannel.

Builder

Added in API level 11
Builder(context: Context!)

Deprecated: use Builder(android.content.Context,java.lang.String) instead. All posted Notifications must specify a NotificationChannel Id.

Public methods

addAction

Added in API level 16
Deprecated in API level 23
open fun addAction(
    icon: Int,
    title: CharSequence!,
    intent: PendingIntent!
): Notification.Builder!

Deprecated: Use addAction(android.app.Notification.Action) instead.

Add an action to this notification. Actions are typically displayed by the system as a button adjacent to the notification content.

Every action must have an icon (32dp square and matching the Holo Dark action bar visual style), a textual label, and a PendingIntent.

A notification in its expanded form can display up to 3 actions, from left to right in the order they were added. Actions will not be displayed when the notification is collapsed, however, so be sure that any essential functions may be accessed by the user in some other way (for example, in the Activity pointed to by contentIntent).

As of Android android.os.Build.VERSION_CODES#S, apps targeting API level android.os.Build.VERSION_CODES#S or higher won't be able to start activities while processing broadcast receivers or services in response to notification action clicks. To launch an activity in those cases, provide a PendingIntent to the activity itself.

As of Android android.os.Build.VERSION_CODES#N, action button icons will not be displayed on action buttons, but are still required and are available to notification listeners, which may display them in other contexts, for example on a wearable device.

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.

addAction

Added in API level 20
open fun addAction(action: Notification.Action!): Notification.Builder

Add an action to this notification. Actions are typically displayed by the system as a button adjacent to the notification content.

Every action must have an icon (32dp square and matching the Holo Dark action bar visual style), a textual label, and a PendingIntent.

A notification in its expanded form can display up to 3 actions, from left to right in the order they were added. Actions will not be displayed when the notification is collapsed, however, so be sure that any essential functions may be accessed by the user in some other way (for example, in the Activity pointed to by contentIntent).

Parameters
action Notification.Action!: The action to add.
Return
Notification.Builder This value cannot be null.

addExtras

Added in API level 20
open fun addExtras(extras: Bundle!): Notification.Builder

Merge additional metadata into this notification.

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

Return
Notification.Builder This value cannot be null.

addPerson

Added in API level 21
Deprecated in API level 28
open fun addPerson(uri: String!): Notification.Builder!

Deprecated: use addPerson(android.app.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 CATEGORY_CALL or CATEGORY_MESSAGE. The addition of people may also cause this notification to appear more prominently in the user interface.

The person should be specified by the String representation of a android.provider.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 android.provider.ContactsContract.PhoneLookup. It is also possible to provide a URI with the schema name: in order to uniquely identify a person without an entry in the contacts database.

Parameters
uri String!: A URI for the person.

addPerson

Added in API level 28
open fun addPerson(person: Person!): Notification.Builder

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 CATEGORY_CALL or 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 Person!: the person to add.
Return
Notification.Builder This value cannot be null.

build

Added in API level 16
open fun build(): Notification

Combine all of the options that have been set and return a new Notification object. If this notification has 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 on the notification builder, if one was set. If the shortcutId's were specified but do not match, an exception is thrown here.

Return
Notification This value cannot be null.

createBigContentView

Added in API level 24
open fun createBigContentView(): RemoteViews!

Construct a RemoteViews for the final big notification layout.

createContentView

Added in API level 24
open fun createContentView(): RemoteViews!

Construct a RemoteViews for the final 1U notification layout. In order: 1. Custom contentView from the caller 2. Style's proposed content view 3. Standard template view

createHeadsUpContentView

Added in API level 24
open fun createHeadsUpContentView(): RemoteViews!

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

extend

Added in API level 20
open fun extend(extender: Notification.Extender!): Notification.Builder

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

Return
Notification.Builder This value cannot be null.

getExtras

Added in API level 20
open fun getExtras(): Bundle!

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.

getNotification

Added in API level 11
Deprecated in API level 16
open fun getNotification(): Notification!

Deprecated: Use build() instead.

getStyle

Added in API level 28
open fun getStyle(): Notification.Style!

Returns the style set by setStyle(android.app.Notification.Style).

recoverBuilder

Added in API level 24
open static fun recoverBuilder(
    context: Context!,
    n: Notification!
): Notification.Builder

Creates a Builder from an existing notification so further changes can be made.

Parameters
context Context!: The context for your application / activity.
n Notification!: The notification to create a Builder from.
Return
Notification.Builder This value cannot be null.

setActions

Added in API level 24
open fun setActions(vararg actions: Notification.Action!): Notification.Builder

Alter the complete list of actions attached to this notification.

Parameters
actions Notification.Action!:
Return
Notification.Builder This value cannot be null.

setAllowSystemGeneratedContextualActions

Added in API level 29
open fun setAllowSystemGeneratedContextualActions(allowed: Boolean): Notification.Builder

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

Return
Notification.Builder This value cannot be null.

setAutoCancel

Added in API level 11
open fun setAutoCancel(autoCancel: Boolean): Notification.Builder

Make this notification automatically dismissed when the user touches it.

Return
Notification.Builder This value cannot be null.

setBadgeIconType

Added in API level 26
open fun setBadgeIconType(icon: Int): Notification.Builder

Sets which icon to display as a badge for this notification. Must be one of BADGE_ICON_NONE, BADGE_ICON_SMALL, BADGE_ICON_LARGE. Note: This value might be ignored, for launchers that don't support badge icons.

Return
Notification.Builder This value cannot be null.

setBubbleMetadata

Added in API level 29
open fun setBubbleMetadata(data: Notification.BubbleMetadata?): Notification.Builder

Sets the 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 bubbles.

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.

Parameters
data Notification.BubbleMetadata?: This value may be null.
Return
Notification.Builder This value cannot be null.

setCategory

Added in API level 21
open fun setCategory(category: String!): Notification.Builder

Set the notification category.

Return
Notification.Builder This value cannot be null.

setChannelId

Added in API level 26
open fun setChannelId(channelId: String!): Notification.Builder

Specifies the channel the notification should be delivered on.

Return
Notification.Builder This value cannot be null.

setChronometerCountDown

Added in API level 24
open fun setChronometerCountDown(countDown: Boolean): Notification.Builder

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.

Return
Notification.Builder This value cannot be null.

setColor

Added in API level 21
open fun setColor(argb: Int): Notification.Builder

Sets Notification#color.

Parameters
argb Int: The accent color to use
Return
Notification.Builder The same Builder. This value cannot be null.

setColorized

Added in API level 26
open fun setColorized(colorize: Boolean): Notification.Builder

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.

Return
Notification.Builder This value cannot be null.

setContent

Added in API level 11
Deprecated in API level 24
open fun setContent(views: RemoteViews!): Notification.Builder!

Deprecated: Deprecated in Java.

Supply a custom RemoteViews to use instead of the platform template. Use setCustomContentView(android.widget.RemoteViews) instead.

setContentInfo

Added in API level 11
Deprecated in API level 24
open fun setContentInfo(info: CharSequence!): Notification.Builder!

Deprecated: use setSubText(java.lang.CharSequence) instead to set a text in the header. For legacy apps targeting a version below android.os.Build.VERSION_CODES#N this field will still show up, but the subtext will take precedence.

A small piece of additional information pertaining to this notification. The platform template will draw this on the last line of the notification, at the far right (to the right of a smallIcon if it has been placed there).

setContentIntent

Added in API level 11
open fun setContentIntent(intent: PendingIntent!): Notification.Builder

Supply a PendingIntent to be sent when the notification is clicked.

As of Android android.os.Build.VERSION_CODES#S, apps targeting API level android.os.Build.VERSION_CODES#S or higher won't be able to start activities while processing broadcast receivers or services in response to notification clicks. To launch an activity in those cases, provide a PendingIntent for the activity itself.

As of android.os.Build.VERSION_CODES#HONEYCOMB, if this field is unset and you have specified a custom RemoteViews with setContent(android.widget.RemoteViews), you can use RemoteViews.setOnClickPendingIntent(int,PendingIntent) to assign PendingIntents to individual views in that custom layout (i.e., to create clickable buttons inside the notification view).

Return
Notification.Builder This value cannot be null.

setContentText

Added in API level 11
open fun setContentText(text: CharSequence!): Notification.Builder

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

Return
Notification.Builder This value cannot be null.

setContentTitle

Added in API level 11
open fun setContentTitle(title: CharSequence!): Notification.Builder

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

Return
Notification.Builder This value cannot be null.

setCustomBigContentView

Added in API level 24
open fun setCustomBigContentView(contentView: RemoteViews!): Notification.Builder

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.

Return
Notification.Builder This value cannot be null.

setCustomContentView

Added in API level 24
open fun setCustomContentView(contentView: RemoteViews!): Notification.Builder

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

Return
Notification.Builder This value cannot be null.

setCustomHeadsUpContentView

Added in API level 24
open fun setCustomHeadsUpContentView(contentView: RemoteViews!): Notification.Builder

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.

Return
Notification.Builder This value cannot be null.

setDefaults

Added in API level 11
Deprecated in API level 26
open fun setDefaults(defaults: Int): Notification.Builder!

Deprecated: use NotificationChannel#enableVibration(boolean) and NotificationChannel#enableLights(boolean) and NotificationChannel#setSound(Uri, AudioAttributes) instead.

Set which notification properties will be inherited from system defaults.

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

For all default values, use DEFAULT_ALL.

setDeleteIntent

Added in API level 11
open fun setDeleteIntent(intent: PendingIntent!): Notification.Builder

Supply a PendingIntent to send when the notification is cleared explicitly by the user.

Return
Notification.Builder This value cannot be null.

setExtras

Added in API level 19
open fun setExtras(extras: Bundle!): Notification.Builder

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 to merge in metadata instead.

Return
Notification.Builder This value cannot be null.

setFlag

Added in API level 30
open fun setFlag(
    mask: Int,
    value: Boolean
): Notification.Builder

Set the value for a notification flag

Parameters
mask Int: Bit mask of the flag Value is either 0 or a combination of android.app.Notification#FLAG_SHOW_LIGHTS, android.app.Notification#FLAG_ONGOING_EVENT, android.app.Notification#FLAG_INSISTENT, android.app.Notification#FLAG_ONLY_ALERT_ONCE, android.app.Notification#FLAG_AUTO_CANCEL, android.app.Notification#FLAG_NO_CLEAR, android.app.Notification#FLAG_FOREGROUND_SERVICE, android.app.Notification#FLAG_HIGH_PRIORITY, android.app.Notification#FLAG_LOCAL_ONLY, android.app.Notification#FLAG_GROUP_SUMMARY, android.app.Notification.FLAG_AUTOGROUP_SUMMARY, android.app.Notification#FLAG_BUBBLE, and android.app.Notification.FLAG_USER_INITIATED_JOB
value Boolean: Status (on/off) of the flag
Return
Notification.Builder The same Builder. This value cannot be null.

setForegroundServiceBehavior

Added in API level 31
open fun setForegroundServiceBehavior(behavior: Int): Notification.Builder

Specify a desired visibility policy for a Notification associated with a foreground service. By default, 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.

Parameters
behavior Int: One of FOREGROUND_SERVICE_DEFAULT, FOREGROUND_SERVICE_IMMEDIATE, or FOREGROUND_SERVICE_DEFERRED Value is android.app.Notification#FOREGROUND_SERVICE_DEFAULT, android.app.Notification#FOREGROUND_SERVICE_IMMEDIATE, or android.app.Notification#FOREGROUND_SERVICE_DEFERRED
Return
Notification.Builder This value cannot be null.

setFullScreenIntent

Added in API level 11
open fun setFullScreenIntent(
    intent: PendingIntent!,
    highPriority: Boolean
): Notification.Builder

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.

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

Apps targeting Build.VERSION_CODES#Q and above will have to request a permission (android.Manifest.permission#USE_FULL_SCREEN_INTENT) in order to use full screen intents.

To be launched as a full screen intent, the notification must also be posted to a channel with importance level set to IMPORTANCE_HIGH or higher.

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.
Return
Notification.Builder This value cannot be null.

setGroup

Added in API level 20
open fun setGroup(groupKey: String!): Notification.Builder

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. A sort order can be specified for group members by using setSortKey.

Parameters
groupKey String!: The group key of the group.
Return
Notification.Builder this object for method chaining This value cannot be null.

setGroupAlertBehavior

Added in API level 26
open fun setGroupAlertBehavior(groupAlertBehavior: Int): Notification.Builder

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 and/or peek on screen, all children in the group should have the group alert behavior GROUP_ALERT_SUMMARY.

The default value is GROUP_ALERT_ALL.

Parameters
groupAlertBehavior Int: Value is android.app.Notification#GROUP_ALERT_ALL, android.app.Notification#GROUP_ALERT_CHILDREN, or android.app.Notification#GROUP_ALERT_SUMMARY
Return
Notification.Builder This value cannot be null.

setGroupSummary

Added in API level 20
open fun setGroupSummary(isGroupSummary: Boolean): Notification.Builder

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. If thereRequires a group key also be set using setGroup. The group summary may be suppressed if too few notifications are included in the group.

Parameters
isGroupSummary Boolean: Whether this notification should be a group summary.
Return
Notification.Builder this object for method chaining This value cannot be null.

setLargeIcon

Added in API level 11
open fun setLargeIcon(b: Bitmap!): Notification.Builder

Add a large icon to the notification content view. In the platform template, this image will be shown either on the right of the notification, with an aspect ratio of up to 16:9, or (when the notification is grouped) on the left in place of the small icon.

Return
Notification.Builder This value cannot be null.

setLargeIcon

Added in API level 23
open fun setLargeIcon(icon: Icon!): Notification.Builder

Add a large icon to the notification content view. In the platform template, this image will be shown either on the right of the notification, with an aspect ratio of up to 16:9, or (when the notification is grouped) on the left in place of the small icon.

Return
Notification.Builder This value cannot be null.

setLights

Added in API level 11
Deprecated in API level 26
open fun setLights(
    argb: Int,
    onMs: Int,
    offMs: Int
): Notification.Builder!

Deprecated: use NotificationChannel#enableLights(boolean) instead.

Set the desired color for the indicator LED on the device, as well as the blink duty cycle (specified in milliseconds). Not all devices will honor all (or even any) of these values.

setLocalOnly

Added in API level 20
open fun setLocalOnly(localOnly: Boolean): Notification.Builder

Set whether or not this notification should not bridge to other devices.

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

Return
Notification.Builder This value cannot be null.

setLocusId

Added in API level 29
open fun setLocusId(locusId: LocusId?): Notification.Builder

Sets the LocusId associated with this notification.

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

Parameters
locusId LocusId?: This value may be null.
Return
Notification.Builder This value cannot be null.

setNumber

Added in API level 11
Deprecated in API level 24
open fun setNumber(number: Int): Notification.Builder

Sets the number of items this notification represents. May be displayed as a badge count for Launchers that support badging.

Return
Notification.Builder This value cannot be null.

setOngoing

Added in API level 11
open fun setOngoing(ongoing: Boolean): Notification.Builder

Set whether this is an "ongoing" notification. Ongoing notifications cannot be dismissed by the user on locked devices, or by notification listeners, and some notifications (call, device management, media) cannot be dismissed on unlocked devices, 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).

Return
Notification.Builder This value cannot be null.

setOnlyAlertOnce

Added in API level 11
open fun setOnlyAlertOnce(onlyAlertOnce: Boolean): Notification.Builder

Set this flag if you would only like the sound, vibrate and ticker to be played if the notification is not already showing. Note that using this flag will stop any ongoing alerting behaviour such as sound, vibration or blinking notification LED.

Return
Notification.Builder This value cannot be null.

setProgress

Added in API level 14
open fun setProgress(
    max: Int,
    progress: Int,
    indeterminate: Boolean
): Notification.Builder

Set the progress this notification represents. The platform template will represent this using a ProgressBar.

Return
Notification.Builder This value cannot be null.

setPublicVersion

Added in API level 21
open fun setPublicVersion(n: Notification!): Notification.Builder

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

Parameters
n Notification!: A replacement notification, presumably with some or all info redacted.
Return
Notification.Builder The same Builder. This value cannot be null.

setRemoteInputHistory

Added in API level 24
open fun setRemoteInputHistory(text: Array<CharSequence!>!): Notification.Builder

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.

Return
Notification.Builder This value cannot be null.

setSettingsText

Added in API level 26
open fun setSettingsText(text: CharSequence!): Notification.Builder

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

Parameters
text CharSequence!:
Return
Notification.Builder This value cannot be null.

setShortcutId

Added in API level 26
open fun setShortcutId(shortcutId: String!): Notification.Builder

From Android 11, messaging notifications (those that use 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 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 String!: the id of the shortcut this notification is linked to
Return
Notification.Builder This value cannot be null.

setShowWhen

Added in API level 17
open fun setShowWhen(show: Boolean): Notification.Builder

Control whether the timestamp set with setWhen is shown in the content view. For apps targeting android.os.Build.VERSION_CODES#N and above, this defaults to false. For earlier apps, the default is true.

Return
Notification.Builder This value cannot be null.

setSmallIcon

Added in API level 11
open fun setSmallIcon(icon: Int): Notification.Builder

Set the small icon resource, which will be used to represent the notification in the status bar. The platform template for the expanded view will draw this icon in the left, unless a large icon has also been specified, in which case the small icon will be moved to the right-hand side.

Parameters
icon Int: A resource ID in the application's package of the drawable to use.
Return
Notification.Builder This value cannot be null.

setSmallIcon

Added in API level 11
open fun setSmallIcon(
    icon: Int,
    level: Int
): Notification.Builder

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.
Return
Notification.Builder This value cannot be null.

setSmallIcon

Added in API level 23
open fun setSmallIcon(icon: Icon!): Notification.Builder

Set the small icon, which will be used to represent the notification in the status bar and content view (unless overridden there by a large icon).

Parameters
icon Icon!: An Icon object to use.
Return
Notification.Builder This value cannot be null.

setSortKey

Added in API level 20
open fun setSortKey(sortKey: String!): Notification.Builder

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.

Return
Notification.Builder This value cannot be null.

setSound

Added in API level 11
Deprecated in API level 26
open fun setSound(sound: Uri!): Notification.Builder!

Deprecated: use NotificationChannel#setSound(Uri, AudioAttributes) instead.

Set the sound to play. It will be played using the default audio attributes for notifications.

setSound

Added in API level 11
Deprecated in API level 21
open fun setSound(
    sound: Uri!,
    streamType: Int
): Notification.Builder!

Deprecated: use NotificationChannel#setSound(Uri, AudioAttributes).

Set the sound to play, along with a specific stream on which to play it. See android.media.AudioManager for the STREAM_ constants.

setSound

Added in API level 21
Deprecated in API level 26
open fun setSound(
    sound: Uri!,
    audioAttributes: AudioAttributes!
): Notification.Builder!

Deprecated: use NotificationChannel#setSound(Uri, AudioAttributes) instead.

Set the sound to play, along with specific audio attributes to use during playback.

setStyle

Added in API level 16
open fun setStyle(style: Notification.Style!): Notification.Builder

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

Parameters
style Notification.Style!: Object responsible for modifying the notification style.
Return
Notification.Builder This value cannot be null.

setSubText

Added in API level 16
open fun setSubText(text: CharSequence!): Notification.Builder

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 android.os.Build.VERSION_CODES#N this information is displayed in the notification header area. On Android versions before android.os.Build.VERSION_CODES#N this will be shown in the third line of text in the platform notification template. You should not be using setProgress(int,int,boolean) at the same time on those versions; they occupy the same place.

Return
Notification.Builder This value cannot be null.

setTicker

Added in API level 11
open fun setTicker(tickerText: CharSequence!): Notification.Builder

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

Return
Notification.Builder This value cannot be null.

setTicker

Added in API level 11
Deprecated in API level 21
open fun setTicker(
    tickerText: CharSequence!,
    views: RemoteViews!
): Notification.Builder!

Deprecated: Deprecated in Java.

Obsolete version of setTicker(java.lang.CharSequence).

setTimeoutAfter

Added in API level 26
open fun setTimeoutAfter(durationMs: Long): Notification.Builder

Specifies a duration in milliseconds after which this notification should be canceled, if it is not already canceled.

Return
Notification.Builder This value cannot be null.

setUsesChronometer

Added in API level 16
open fun setUsesChronometer(b: Boolean): Notification.Builder

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). The counter can also be set to count down to when when using setChronometerCountDown(boolean).

Return
Notification.Builder This value cannot be null.

setVibrate

Added in API level 11
Deprecated in API level 26
open fun setVibrate(pattern: LongArray!): Notification.Builder!

Deprecated: use NotificationChannel#setVibrationPattern(long[]) instead.

Set the vibration pattern to use. See android.os.Vibrator#vibrate(long[], int) for a discussion of the pattern parameter.

A notification that vibrates is more likely to be presented as a heads-up notification.

setVisibility

Added in API level 21
open fun setVisibility(visibility: Int): Notification.Builder

Specify the value of visibility.

Parameters
visibility Int: Value is android.app.Notification#VISIBILITY_PUBLIC, android.app.Notification#VISIBILITY_PRIVATE, or android.app.Notification#VISIBILITY_SECRET
Return
Notification.Builder The same Builder. This value cannot be null.

setWhen

Added in API level 11
open fun setWhen(when: Long): Notification.Builder

Add a timestamp pertaining to the notification (usually the time the event occurred). For apps targeting android.os.Build.VERSION_CODES#N and above, this time is not shown anymore by default and must be opted into by using android.app.Notification.Builder#setShowWhen(boolean)

Return
Notification.Builder This value cannot be null.