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!)

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

Constructs a new Builder with the defaults:

Public methods
open Notification.Builder

Add an action to this notification.

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

Add an action to this notification.

open Notification.Builder
addExtras(extras: Bundle!)

Merge additional metadata into this notification.

open Notification.Builder
addPerson(person: Person!)

Add a person that is relevant to this notification.

open Notification.Builder!

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 representing the expanded notification layout.

open RemoteViews!

Construct a RemoteViews representing the standard notification layout.

open RemoteViews!

Construct a RemoteViews representing the 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(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
setHasSummarizedContent(hasSummarizedContent: Boolean)

Sets whether this notification contains text that was computationally summarized from other sources.

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
setRequestPromotedOngoing(requestPromotedOngoing: Boolean)

Set whether this notification is requesting to be a promoted ongoing notification.

open Notification.Builder

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

open Notification.Builder
setShortCriticalText(shortCriticalText: String?)

Sets a very short string summarizing the most critical information contained in the notification.

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, which will be used to represent the notification in the status bar.

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
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!, audioAttributes: AudioAttributes!)

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

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

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