Google は、黒人コミュニティに対する人種平等の促進に取り組んでいます。取り組みを見る

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)

createBigContentView

@Nullable open fun createBigContentView(): RemoteViews?

Construct a RemoteViews for the final big notification layout.

createContentView

@Nullable open fun createContentView(): RemoteViews?

Construct a RemoteViews for the final notification layout.

createHeadsUpContentView

@Nullable open fun createHeadsUpContentView(): RemoteViews?

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

extend

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

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

getExtras

@NonNull 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

@NonNull open fun getNotification(): Notification

Deprecated: Use build() instead.

setAllowSystemGeneratedContextualActions

@NonNull open fun setAllowSystemGeneratedContextualActions(allowed: Boolean): NotificationCompat.Builder

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

setAutoCancel

@NonNull open fun setAutoCancel(autoCancel: Boolean): NotificationCompat.Builder

Setting this flag will make it so the notification is automatically canceled when the user clicks it in the panel. The PendingIntent set with setDeleteIntent will be broadcast when the notification is canceled.

setBadgeIconType

@NonNull open fun setBadgeIconType(icon: Int): NotificationCompat.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.

setBubbleMetadata

@NonNull open fun setBubbleMetadata(@Nullable data: NotificationCompat.BubbleMetadata?): NotificationCompat.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.

setCategory

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

Set the notification category.

Must be one of the predefined notification categories (see the CATEGORY_* constants in Notification) that best describes this notification. May be used by the system for ranking and filtering.

setChannelId

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

Specifies the channel the notification should be delivered on. No-op on versions prior to android.os.Build.VERSION_CODES#O.

setChronometerCountDown

@RequiresApi(24) @NonNull open fun setChronometerCountDown(countsDown: Boolean): NotificationCompat.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.

setColor

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

Sets Notification#color.

Parameters
argb Int: The accent color to use
Return
NotificationCompat.Builder The same Builder.

setColorized

@NonNull open fun setColorized(colorize: Boolean): NotificationCompat.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.

Calling this method on any version prior to android.os.Build.VERSION_CODES#O will not have an effect on the notification and it won't be colorized.

See Also

setContent

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

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

setContentInfo

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

A small piece of additional information pertaining to this notification. Where this text is displayed varies between platform versions. Use setSubText(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.

setContentIntent

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

Supply a PendingIntent to send when the notification is clicked. If you do not supply an intent, you can now add PendingIntents to individual views to be launched when clicked by calling RemoteViews.setOnClickPendingIntent(int,PendingIntent). Be sure to read Notification.contentIntent for how to correctly use this.

setContentText

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

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

setContentTitle

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

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

setCustomBigContentView

@NonNull open fun setCustomBigContentView(@Nullable contentView: RemoteViews?): NotificationCompat.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. No-op on versions prior to android.os.Build.VERSION_CODES#JELLY_BEAN.

setCustomContentView

@NonNull open fun setCustomContentView(@Nullable contentView: RemoteViews?): NotificationCompat.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.

setCustomHeadsUpContentView

@NonNull open fun setCustomHeadsUpContentView(@Nullable contentView: RemoteViews?): NotificationCompat.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. No-op on versions prior to android.os.Build.VERSION_CODES#LOLLIPOP.

setDefaults

@NonNull open fun setDefaults(defaults: Int): NotificationCompat.Builder

Set the default notification options that will be used.

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

For all default values, use Notification#DEFAULT_ALL.

On platforms Build.VERSION_CODES#O and above this value is ignored in favor of the values set on the notification's channel. On older platforms, this value is still used, so it is still required for apps supporting those platforms.

setDeleteIntent

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

Supply a PendingIntent to send when the notification is cleared by the user directly from the notification panel. For example, this intent is sent when the user clicks the "Clear all" button, or the individual "X" buttons on notifications. This intent is not sent when the application calls android.app.NotificationManager#cancel.

setExtras

@NonNull open fun setExtras(@Nullable extras: Bundle?): NotificationCompat.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.

setFullScreenIntent

@NonNull open fun setFullScreenIntent(
    @Nullable intent: PendingIntent?,
    highPriority: Boolean
): NotificationCompat.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.

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

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.

setGroup

@NonNull open fun setGroup(@Nullable groupKey: String?): NotificationCompat.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
NotificationCompat.Builder this object for method chaining

setGroupAlertBehavior

@NonNull open fun setGroupAlertBehavior(groupAlertBehavior: Int): NotificationCompat.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, all children in the group should have the group alert behavior GROUP_ALERT_SUMMARY.

The default value is GROUP_ALERT_ALL.

setGroupSummary

@NonNull open fun setGroupSummary(isGroupSummary: Boolean): NotificationCompat.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. Requires a group key also be set using setGroup.

Parameters
isGroupSummary Boolean: Whether this notification should be a group summary.
Return
NotificationCompat.Builder this object for method chaining

setLargeIcon

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

Set the large icon that is shown in the notification.

setLights

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

Set the argb value that you would like the LED on the device to blink, as well as the rate. The rate is specified in terms of the number of milliseconds to be on and then the number of milliseconds to be off.

On platforms Build.VERSION_CODES#O and above this value is ignored in favor of the value set on the notification's channel. On older platforms, this value is still used, so it is still required for apps supporting those platforms.

setLocalOnly

@NonNull open fun setLocalOnly(b: Boolean): NotificationCompat.Builder

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

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

setLocusId

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

Sets the LocusIdCompat associated with this notification.

This method should be called when the LocusIdCompat is used in other places (such as androidx.core.content.pm.ShortcutInfoCompat and android.view.contentcapture.ContentCaptureContext) so the device's intelligence services can correlate them.

setNotificationSilent

@NonNull open fun setNotificationSilent(): NotificationCompat.Builder

Deprecated: use setSilent(boolean)

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

setNumber

@NonNull open fun setNumber(number: Int): NotificationCompat.Builder

Sets the number of items this notification represents. On the latest platforms, this may be displayed as a badge count for Launchers that support badging. Prior to android.os.Build.VERSION_CODES#O it could be shown in the header. And prior to android.os.Build.VERSION_CODES#N this was shown in the notification on the right side.

setOngoing

@NonNull open fun setOngoing(ongoing: Boolean): NotificationCompat.Builder

Set whether this is an ongoing notification. Ongoing notifications cannot be dismissed by the user, 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).

setOnlyAlertOnce

@NonNull open fun setOnlyAlertOnce(onlyAlertOnce: Boolean): NotificationCompat.Builder

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

setPriority

@NonNull open fun setPriority(pri: Int): NotificationCompat.Builder

Set the relative priority for this notification.

Priority is an indication of how much of the user's valuable attention should be consumed by this notification. Low-priority notifications may be hidden from the user in certain situations, while the user might be interrupted for a higher-priority notification. The system sets a notification's priority based on various factors including the setPriority value. The effect may differ slightly on different platforms.

On platforms Build.VERSION_CODES#O and above this value is ignored in favor of the importance value set on the notification's channel. On older platforms, this value is still used, so it is still required for apps supporting those platforms.

Parameters
pri Int: Relative priority for this notification. Must be one of the priority constants defined by NotificationCompat. Acceptable values range from NotificationCompat#PRIORITY_MIN (-2) to NotificationCompat#PRIORITY_MAX (2).

setProgress

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

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

setPublicVersion

@NonNull open fun setPublicVersion(@Nullable n: Notification?): NotificationCompat.Builder

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

Parameters
n Notification?: A replacement notification, presumably with some or all info redacted.
Return
NotificationCompat.Builder The same Builder.

setRemoteInputHistory

@NonNull open fun setRemoteInputHistory(@Nullable text: Array<CharSequence!>?): NotificationCompat.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.

setSettingsText

@NonNull open fun setSettingsText(@Nullable text: CharSequence?): NotificationCompat.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.

Prior to Build.VERSION_CODES#O this field has no effect.

setShortcutId

@NonNull open fun setShortcutId(@Nullable shortcutId: String?): NotificationCompat.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

setShortcutInfo

@NonNull open fun setShortcutInfo(@Nullable shortcutInfo: ShortcutInfoCompat?): NotificationCompat.Builder

Populates this notification with given ShortcutInfoCompat.

Sets shortcutId based on the given shortcut. In addition, it also sets locusId and contentTitle if they were empty.

setShowWhen

@NonNull open fun setShowWhen(show: Boolean): NotificationCompat.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.

setSilent

@NonNull open fun setSilent(silent: Boolean): NotificationCompat.Builder

If true, silences this instance of the notification, regardless of the sounds or vibrations set on the notification or notification channel. If false, then the normal sound and vibration logic applies. Defaults to false.

setSmallIcon

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

Set the small icon to use in the notification layouts. Different classes of devices may return different sizes. See the UX guidelines for more information on how to design these icons.

Parameters
icon IconCompat: The small Icon object to use

setSmallIcon

@NonNull open fun setSmallIcon(icon: Int): NotificationCompat.Builder

Set the small icon to use in the notification layouts. Different classes of devices may return different sizes. See the UX guidelines for more information on how to design these icons.

Parameters
icon Int: A resource ID in the application's package of the drawable to use.

setSmallIcon

@NonNull open fun setSmallIcon(
    icon: Int,
    level: Int
): NotificationCompat.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.

setSortKey

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

setSound

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

Set the sound to play. It will play on the default stream.

On some platforms, a notification that is noisy is more likely to be presented as a heads-up notification.

On platforms Build.VERSION_CODES#O and above this value is ignored in favor of the value set on the notification's channel. On older platforms, this value is still used, so it is still required for apps supporting those platforms.

setSound

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

Set the sound to play. It will play on the stream you supply.

On some platforms, a notification that is noisy is more likely to be presented as a heads-up notification.

On platforms Build.VERSION_CODES#O and above this value is ignored in favor of the value set on the notification's channel. On older platforms, this value is still used, so it is still required for apps supporting those platforms.

setStyle

@NonNull open fun setStyle(@Nullable style: NotificationCompat.Style?): NotificationCompat.Builder

Add a rich notification style to be applied at build time.
If the platform does not provide rich notification styles, this method has no effect. The user will always see the normal notification style.

Parameters
style NotificationCompat.Style?: Object responsible for modifying the notification style.

setSubText

@NonNull open fun setSubText(@Nullable text: CharSequence?): NotificationCompat.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.

setTicker

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

Sets the "ticker" text which is sent to accessibility services. Prior to Build.VERSION_CODES#LOLLIPOP, sets the text that is displayed in the status bar when the notification first arrives.

setTicker

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

Deprecated: use setTicker(CharSequence)

Sets the "ticker" text which is sent to accessibility services. Prior to Build.VERSION_CODES#LOLLIPOP, sets the text that is displayed in the status bar when the notification first arrives, and also a RemoteViews object that may be displayed instead on some devices.

setTimeoutAfter

@NonNull open fun setTimeoutAfter(durationMs: Long): NotificationCompat.Builder

Specifies the time at which this notification should be canceled, if it is not already canceled. No-op on versions prior to android.os.Build.VERSION_CODES#O.

setUsesChronometer

@NonNull open fun setUsesChronometer(b: Boolean): NotificationCompat.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).

setVibrate

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

Set the vibration pattern to use.

On some platforms, a notification that vibrates is more likely to be presented as a heads-up notification.

On platforms Build.VERSION_CODES#O and above this value is ignored in favor of the value set on the notification's channel. On older platforms, this value is still used, so it is still required for apps supporting those platforms.

setVisibility

@NonNull open fun setVisibility(visibility: Int): NotificationCompat.Builder

Sets Notification#visibility.

Parameters
visibility Int: One of Notification#VISIBILITY_PRIVATE (the default), Notification#VISIBILITY_PUBLIC, or Notification#VISIBILITY_SECRET.

setWhen

@NonNull open fun setWhen(when: Long): NotificationCompat.Builder

Set the time that the event occurred. Notifications in the panel are sorted by this time.

For apps targeting android.os.Build.VERSION_CODES#N and above, this time is not shown anymore by default and must be opted into using setShowWhen(boolean)

Protected methods

limitCharSequenceLength

@Nullable protected open static fun limitCharSequenceLength(@Nullable cs: CharSequence?): CharSequence?

Properties

mPeople

var mPeople: ArrayList<String!>!

Deprecated: This field was not meant to be public.