Google se compromete a impulsar la igualdad racial para las comunidades afrodescendientes. Obtén información al respecto.

Builder

open class Builder
kotlin.Any
   ↳ androidx.core.app.NotificationCompat.Builder

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 android.app.Activity in your app, and you should always start that android.app.Activity when users click the notification. To do this, use the setContentIntent() method.

Summary

Public constructors
<init>(@NonNull context: Context, @NonNull notification: Notification)

Creates a NotificationCompat.

<init>(@NonNull context: Context, @NonNull channelId: String)

Constructor.

<init>(@NonNull context: Context)

Public methods
open NotificationCompat.Builder
addAction(icon: Int, @Nullable title: CharSequence?, @Nullable intent: PendingIntent?)

Add an action to this notification.

open NotificationCompat.Builder

Add an action to this notification.

open NotificationCompat.Builder
addExtras(@Nullable extras: Bundle?)

Merge additional metadata into this notification.

open NotificationCompat.Builder
addInvisibleAction(icon: Int, @Nullable title: CharSequence?, @Nullable intent: PendingIntent?)

Add an invisible action to this notification.

open NotificationCompat.Builder

Add an invisible action to this notification.

open NotificationCompat.Builder
addPerson(@Nullable uri: String?)

Add a person that is relevant to this notification.

open NotificationCompat.Builder
addPerson(@Nullable 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 NotificationCompat.Builder

Clear any actions added via #addAction

open NotificationCompat.Builder

Clear any invisible actions added via #addInvisibleAction

open NotificationCompat.Builder

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

open RemoteViews?

Construct a RemoteViews for the final big notification layout.

open RemoteViews?

Construct a RemoteViews for the final notification layout.

open RemoteViews?

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

open NotificationCompat.Builder
extend(@NonNull extender: NotificationCompat.Extender)

Apply an extender to this notification builder.

open Bundle

Get the current metadata Bundle used by this notification Builder.

open Notification

open NotificationCompat.Builder

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

open NotificationCompat.Builder
setAutoCancel(autoCancel: Boolean)

Setting this flag will make it so the notification is automatically canceled when the user clicks it in the panel.

open NotificationCompat.Builder

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

open NotificationCompat.Builder

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

open NotificationCompat.Builder
setCategory(@Nullable category: String?)

Set the notification category.

open NotificationCompat.Builder
setChannelId(@NonNull channelId: String)

Specifies the channel the notification should be delivered on.

open NotificationCompat.Builder

Sets the Chronometer to count down instead of counting up.

open NotificationCompat.Builder
setColor(@ColorInt argb: Int)

Sets Notification#color.

open NotificationCompat.Builder
setColorized(colorize: Boolean)

Set whether this notification should be colorized.

open NotificationCompat.Builder
setContent(@Nullable views: RemoteViews?)

Supply a custom RemoteViews to use instead of the standard one.

open NotificationCompat.Builder
setContentInfo(@Nullable info: CharSequence?)

A small piece of additional information pertaining to this notification.

open NotificationCompat.Builder
setContentIntent(@Nullable intent: PendingIntent?)

Supply a PendingIntent to send when the notification is clicked.

open NotificationCompat.Builder
setContentText(@Nullable text: CharSequence?)

Set the text (second row) of the notification, in a standard notification.

open NotificationCompat.Builder
setContentTitle(@Nullable title: CharSequence?)

Set the title (first row) of the notification, in a standard notification.

open NotificationCompat.Builder
setCustomBigContentView(@Nullable contentView: RemoteViews?)

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

open NotificationCompat.Builder
setCustomContentView(@Nullable contentView: RemoteViews?)

Supply custom RemoteViews to use instead of the platform template.

open NotificationCompat.Builder
setCustomHeadsUpContentView(@Nullable contentView: RemoteViews?)

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

open NotificationCompat.Builder
setDefaults(defaults: Int)

Set the default notification options that will be used.

open NotificationCompat.Builder
setDeleteIntent(@Nullable intent: PendingIntent?)

Supply a PendingIntent to send when the notification is cleared by the user directly from the notification panel.

open NotificationCompat.Builder
setExtras(@Nullable extras: Bundle?)

Set metadata for this notification.

open NotificationCompat.Builder
setFullScreenIntent(@Nullable intent: PendingIntent?, highPriority: Boolean)

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

open NotificationCompat.Builder
setGroup(@Nullable groupKey: String?)

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

open NotificationCompat.Builder
setGroupAlertBehavior(groupAlertBehavior: Int)

Sets the group alert behavior for this notification.

open NotificationCompat.Builder
setGroupSummary(isGroupSummary: Boolean)

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

open NotificationCompat.Builder
setLargeIcon(@Nullable icon: Bitmap?)

Set the large icon that is shown in the notification.

open NotificationCompat.Builder
setLights(@ColorInt argb: Int, onMs: Int, offMs: Int)

Set the argb value that you would like the LED on the device to blink, as well as the rate.

open NotificationCompat.Builder

Set whether or not this notification is only relevant to the current device.

open NotificationCompat.Builder
setLocusId(@Nullable locusId: LocusIdCompat?)

Sets the LocusIdCompat associated with this notification.

open NotificationCompat.Builder

Silences this instance of the notification, regardless of the sounds or vibrations set on the notification or notification channel.

open NotificationCompat.Builder
setNumber(number: Int)

Sets the number of items this notification represents.

open NotificationCompat.Builder
setOngoing(ongoing: Boolean)

Set whether this is an ongoing notification.

open NotificationCompat.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 NotificationCompat.Builder

Set the relative priority for this notification.

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

Set the progress this notification represents, which may be represented as a android.widget.ProgressBar.

open NotificationCompat.Builder

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

open NotificationCompat.Builder

Set the remote input history.

open NotificationCompat.Builder
setSettingsText(@Nullable text: CharSequence?)

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

open NotificationCompat.Builder
setShortcutId(@Nullable 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 NotificationCompat.Builder
setShortcutInfo(@Nullable shortcutInfo: ShortcutInfoCompat?)

Populates this notification with given ShortcutInfoCompat.

open NotificationCompat.Builder

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

open NotificationCompat.Builder
setSilent(silent: Boolean)

If true, silences this instance of the notification, regardless of the sounds or vibrations set on the notification or notification channel.

open NotificationCompat.Builder
setSmallIcon(@NonNull icon: IconCompat)

Set the small icon to use in the notification layouts.

open NotificationCompat.Builder

Set the small icon to use in the notification layouts.

open NotificationCompat.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 NotificationCompat.Builder
setSortKey(@Nullable sortKey: String?)

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

open NotificationCompat.Builder
setSound(@Nullable sound: Uri?)

Set the sound to play.

open NotificationCompat.Builder
setSound(@Nullable sound: Uri?, streamType: Int)

Set the sound to play.

open NotificationCompat.Builder

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

open NotificationCompat.Builder
setSubText(@Nullable text: CharSequence?)

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

open NotificationCompat.Builder
setTicker(@Nullable tickerText: CharSequence?)

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

open NotificationCompat.Builder
setTicker(@Nullable tickerText: CharSequence?, @Nullable views: RemoteViews?)

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

open NotificationCompat.Builder
setTimeoutAfter(durationMs: Long)

Specifies the time at which this notification should be canceled, if it is not already canceled.

open NotificationCompat.Builder

Show the Notification#when field as a stopwatch.

open NotificationCompat.Builder
setVibrate(@Nullable pattern: LongArray?)

Set the vibration pattern to use.

open NotificationCompat.Builder
setVisibility(visibility: Int)

Sets Notification#visibility.

open NotificationCompat.Builder
setWhen(when: Long)

Set the time that the event occurred.

Protected methods
open static CharSequence?

Properties
ArrayList<String!>!

Public constructors

<init>

Builder(
    @NonNull context: Context,
    @NonNull 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.

<init>

Builder(
    @NonNull context: Context,
    @NonNull channelId: String)

Constructor. Automatically sets the when field to System.currentTimeMillis() and the audio stream to the Notification#STREAM_DEFAULT.

Parameters
context Context: A Context that will be used 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.

<init>

Builder(@NonNull context: Context)

Deprecated: use Builder(Context, String) instead. All posted notifications must specify a NotificationChannel ID.

Public methods

addAction

@NonNull open fun addAction(
    icon: Int,
    @Nullable title: CharSequence?,
    @Nullable intent: PendingIntent?
): NotificationCompat.Builder

Add an action to this notification. Actions are typically displayed by the system as a button adjacent to the notification content.
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. To ensure that an action button's functionality is always available, first implement the functionality in the android.app.Activity that starts when a user clicks the notification (see setContentIntent()), and then enhance the notification by implementing the same functionality with #addAction.

Parameters
icon Int: Resource ID of a drawable that represents the action.
title CharSequence?: Text describing the action.
intent PendingIntent?: android.app.PendingIntent to be fired when the action is invoked.

addAction

@NonNull open fun addAction(@Nullable action: NotificationCompat.Action?): NotificationCompat.Builder

Add an action to this notification. Actions are typically displayed by the system as a button adjacent to the notification content.
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. To ensure that an action button's functionality is always available, first implement the functionality in the android.app.Activity that starts when a user clicks the notification (see setContentIntent()), and then enhance the notification by implementing the same functionality with #addAction.

Parameters
action NotificationCompat.Action?: The action to add.

addExtras

@NonNull open fun addExtras(@Nullable extras: Bundle?): NotificationCompat.Builder

Merge additional metadata into this notification.

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

addInvisibleAction

@RequiresApi(21) @NonNull open fun addInvisibleAction(
    icon: Int,
    @Nullable title: CharSequence?,
    @Nullable intent: PendingIntent?
): NotificationCompat.Builder

Add an invisible action to this notification. Invisible actions are never displayed by the system, but can be retrieved and used by other application listening to system notifications. Invisible actions are supported from Android 4.4.4 (API 20) and can be retrieved using NotificationCompat#getInvisibleActions(Notification).

Parameters
icon Int: Resource ID of a drawable that represents the action.
title CharSequence?: Text describing the action.
intent PendingIntent?: android.app.PendingIntent to be fired when the action is invoked.

addInvisibleAction

@RequiresApi(21) @NonNull open fun addInvisibleAction(@Nullable action: NotificationCompat.Action?): NotificationCompat.Builder

Add an invisible action to this notification. Invisible actions are never displayed by the system, but can be retrieved and used by other application listening to system notifications. Invisible actions are supported from Android 4.4.4 (API 20) and can be retrieved using NotificationCompat#getInvisibleActions(Notification).

Parameters
action NotificationCompat.Action?: The action to add.

addPerson

@NonNull open fun addPerson(@Nullable uri: String?): NotificationCompat.Builder

Deprecated: use addPerson(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, and 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.

Parameters
uri String?: A URI for the person.

addPerson

@NonNull open fun addPerson(@Nullable person: Person?): NotificationCompat.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.

build

@NonNull open fun build(): Notification

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

clearActions

@NonNull open fun clearActions(): NotificationCompat.Builder

Clear any actions added via #addAction

clearInvisibleActions

@NonNull open fun clearInvisibleActions(): NotificationCompat.Builder

Clear any invisible actions added via #addInvisibleAction

clearPeople

@NonNull open fun clearPeople(): NotificationCompat.Builder

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