Notification.Builder
public
static
class
Notification.Builder
extends Object
| java.lang.Object | |
| ↳ | 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
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 | |
|---|---|
Notification.Builder(Context context, String channelId)
Constructs a new Builder with the defaults: |
|
Notification.Builder(Context context)
This constructor was deprecated
in API level O.
use |
|
Public methods | |
|---|---|
Notification.Builder
|
addAction(int icon, CharSequence title, PendingIntent intent)
This method was deprecated
in API level 23.
Use |
Notification.Builder
|
addAction(Notification.Action action)
Add an action to this notification. |
Notification.Builder
|
addExtras(Bundle extras)
Merge additional metadata into this notification. |
Notification.Builder
|
addPerson(String uri)
Add a person that is relevant to this notification. |
Notification
|
build()
Combine all of the options that have been set and return a new |
RemoteViews
|
createBigContentView()
Construct a RemoteViews for the final big notification layout. |
RemoteViews
|
createContentView()
Construct a RemoteViews for the final 1U notification layout. |
RemoteViews
|
createHeadsUpContentView()
Construct a RemoteViews for the final heads-up notification layout. |
Notification.Builder
|
extend(Notification.Extender extender)
Apply an extender to this notification builder. |
Bundle
|
getExtras()
Get the current metadata Bundle used by this notification Builder. |
Notification
|
getNotification()
This method was deprecated
in API level 16.
Use |
static
Notification.Builder
|
recoverBuilder(Context context, Notification n)
Creates a Builder from an existing notification so further changes can be made. |
Notification.Builder
|
setActions(Action... actions)
Alter the complete list of actions attached to this notification. |
Notification.Builder
|
setAutoCancel(boolean autoCancel)
Make this notification automatically dismissed when the user touches it. |
Notification.Builder
|
setBadgeIconType(int icon)
Sets which icon to display as a badge for this notification. |
Notification.Builder
|
setCategory(String category)
Set the notification category. |
Notification.Builder
|
setChannelId(String channelId)
Specifies the channel the notification should be delivered on. |
Notification.Builder
|
setChronometerCountDown(boolean countDown)
Sets the Chronometer to count down instead of counting up. |
Notification.Builder
|
setColor(int argb)
Sets |
Notification.Builder
|
setColorized(boolean colorize)
Set whether this notification should be colorized. |
Notification.Builder
|
setContent(RemoteViews views)
Supply a custom RemoteViews to use instead of the platform template. |
Notification.Builder
|
setContentInfo(CharSequence info)
This method was deprecated
in API level 24.
use |
Notification.Builder
|
setContentIntent(PendingIntent intent)
Supply a |
Notification.Builder
|
setContentText(CharSequence text)
Set the second line of text in the platform notification template. |
Notification.Builder
|
setContentTitle(CharSequence title)
Set the first line of text in the platform notification template. |
Notification.Builder
|
setCustomBigContentView(RemoteViews contentView)
Supply custom RemoteViews to use instead of the platform template in the expanded form. |
Notification.Builder
|
setCustomContentView(RemoteViews contentView)
Supply custom RemoteViews to use instead of the platform template. |
Notification.Builder
|
setCustomHeadsUpContentView(RemoteViews contentView)
Supply custom RemoteViews to use instead of the platform template in the heads up dialog. |
Notification.Builder
|
setDefaults(int defaults)
This method was deprecated
in API level O.
use |
Notification.Builder
|
setDeleteIntent(PendingIntent intent)
Supply a |
Notification.Builder
|
setExtras(Bundle extras)
Set metadata for this notification. |
Notification.Builder
|
setFullScreenIntent(PendingIntent intent, boolean highPriority)
An intent to launch instead of posting the notification to the status bar. |
Notification.Builder
|
setGroup(String groupKey)
Set this notification to be part of a group of notifications sharing the same key. |
Notification.Builder
|
setGroupAlertBehavior(int groupAlertBehavior)
Sets the group alert behavior for this notification. |
Notification.Builder
|
setGroupSummary(boolean isGroupSummary)
Set this notification to be the group summary for a group of notifications. |
Notification.Builder
|
setLargeIcon(Bitmap b)
Add a large icon to the notification content view. |
Notification.Builder
|
setLargeIcon(Icon icon)
Add a large icon to the notification content view. |
Notification.Builder
|
setLights(int argb, int onMs, int offMs)
This method was deprecated
in API level O.
use |
Notification.Builder
|
setLocalOnly(boolean localOnly)
Set whether or not this notification should not bridge to other devices. |
Notification.Builder
|
setNumber(int number)
Sets the number of items this notification represents. |
Notification.Builder
|
setOngoing(boolean ongoing)
Set whether this is an "ongoing" notification. |
Notification.Builder
|
setOnlyAlertOnce(boolean onlyAlertOnce)
Set this flag if you would only like the sound, vibrate and ticker to be played if the notification is not already showing. |
Notification.Builder
|
setPriority(int pri)
This method was deprecated
in API level O.
use |
Notification.Builder
|
setProgress(int max, int progress, boolean indeterminate)
Set the progress this notification represents. |
Notification.Builder
|
setPublicVersion(Notification n)
Supply a replacement Notification whose contents should be shown in insecure contexts (i.e. |
Notification.Builder
|
setRemoteInputHistory(CharSequence[] text)
Set the remote input history. |
Notification.Builder
|
setSettingsText(CharSequence text)
Provides text that will appear as a link to your application's settings. |
Notification.Builder
|
setShortcutId(String shortcutId)
If this notification is duplicative of a Launcher shortcut, sets the
|
Notification.Builder
|
setShowWhen(boolean show)
Control whether the timestamp set with |
Notification.Builder
|
setSmallIcon(int icon, int level)
A variant of |
Notification.Builder
|
setSmallIcon(int icon)
Set the small icon resource, which will be used to represent the notification in the status bar. |
Notification.Builder
|
setSmallIcon(Icon icon)
Set the small icon, which will be used to represent the notification in the
status bar and content view (unless overriden there by a
|
Notification.Builder
|
setSortKey(String sortKey)
Set a sort key that orders this notification among other notifications from the same package. |
Notification.Builder
|
setSound(Uri sound, AudioAttributes audioAttributes)
This method was deprecated
in API level O.
use |
Notification.Builder
|
setSound(Uri sound)
This method was deprecated
in API level O.
use |
Notification.Builder
|
setSound(Uri sound, int streamType)
This method was deprecated
in API level 21.
use |
Notification.Builder
|
setStyle(Notification.Style style)
Add a rich notification style to be applied at build time. |
Notification.Builder
|
setSubText(CharSequence text)
This provides some additional information that is displayed in the notification. |
Notification.Builder
|
setTicker(CharSequence tickerText, RemoteViews views)
Obsolete version of |
Notification.Builder
|
setTicker(CharSequence tickerText)
Set the "ticker" text which is sent to accessibility services. |
Notification.Builder
|
setTimeoutAfter(long durationMs)
Specifies a duration in milliseconds after which this notification should be canceled, if it is not already canceled. |
Notification.Builder
|
setUsesChronometer(boolean b)
Show the |
Notification.Builder
|
setVibrate(long[] pattern)
This method was deprecated
in API level O.
use |
Notification.Builder
|
setVisibility(int visibility)
Specify the value of |
Notification.Builder
|
setWhen(long when)
Add a timestamp pertaining to the notification (usually the time the event occurred). |
Inherited methods | |
|---|---|
java.lang.Object
| |
Public constructors
Notification.Builder
Notification.Builder (Context context, String channelId)
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 createNotificationChannel(NotificationChannel).
|
Notification.Builder
Notification.Builder (Context context)
This constructor was deprecated
in API level O.
use Notification.Builder(Context, String)
instead. All posted Notifications must specify a NotificationChannel Id.
| Parameters | |
|---|---|
context |
Context |
Public methods
addAction
Notification.Builder addAction (int icon, CharSequence title, PendingIntent intent)
This method was deprecated
in API level 23.
Use addAction(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).
| 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. |
| Returns | |
|---|---|
Notification.Builder |
|
addAction
Notification.Builder addAction (Notification.Action action)
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.
|
| Returns | |
|---|---|
Notification.Builder |
|
addExtras
Notification.Builder addExtras (Bundle extras)
Merge additional metadata into this notification.
Values within the Bundle will replace existing extras values in this Builder.
| Parameters | |
|---|---|
extras |
Bundle |
| Returns | |
|---|---|
Notification.Builder |
|
See also:
addPerson
Notification.Builder addPerson (String uri)
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
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 ContactsContract.PhoneLookup.
| Parameters | |
|---|---|
uri |
String: A URI for the person. |
| Returns | |
|---|---|
Notification.Builder |
|
See also:
build
Notification build ()
Combine all of the options that have been set and return a new Notification
object.
| Returns | |
|---|---|
Notification |
|
createBigContentView
RemoteViews createBigContentView ()
Construct a RemoteViews for the final big notification layout.
| Returns | |
|---|---|
RemoteViews |
|
createContentView
RemoteViews createContentView ()
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
| Returns | |
|---|---|
RemoteViews |
|
createHeadsUpContentView
RemoteViews createHeadsUpContentView ()
Construct a RemoteViews for the final heads-up notification layout.
| Returns | |
|---|---|
RemoteViews |
|
extend
Notification.Builder extend (Notification.Extender extender)
Apply an extender to this notification builder. Extenders may be used to add metadata or change options on this builder.
| Parameters | |
|---|---|
extender |
Notification.Extender |
| Returns | |
|---|---|
Notification.Builder |
|
getExtras
Bundle getExtras ()
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.
| Returns | |
|---|---|
Bundle |
|
See also:
getNotification
Notification getNotification ()
This method was deprecated
in API level 16.
Use build() instead.
| Returns | |
|---|---|
Notification |
|
recoverBuilder
Notification.Builder recoverBuilder (Context context, Notification n)
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.
|
| Returns | |
|---|---|
Notification.Builder |
|
setActions
Notification.Builder setActions (Action... actions)
Alter the complete list of actions attached to this notification.
| Returns | |
|---|---|
Notification.Builder |
|
See also:
setAutoCancel
Notification.Builder setAutoCancel (boolean autoCancel)
Make this notification automatically dismissed when the user touches it.
| Parameters | |
|---|---|
autoCancel |
boolean |
| Returns | |
|---|---|
Notification.Builder |
|
See also:
setBadgeIconType
Notification.Builder setBadgeIconType (int icon)
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.
| Parameters | |
|---|---|
icon |
int |
| Returns | |
|---|---|
Notification.Builder |
|
setCategory
Notification.Builder setCategory (String category)
Set the notification category.
| Parameters | |
|---|---|
category |
String |
| Returns | |
|---|---|
Notification.Builder |
|
See also:
setChannelId
Notification.Builder setChannelId (String channelId)
Specifies the channel the notification should be delivered on.
| Parameters | |
|---|---|
channelId |
String |
| Returns | |
|---|---|
Notification.Builder |
|
setChronometerCountDown
Notification.Builder setChronometerCountDown (boolean countDown)
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.
| Parameters | |
|---|---|
countDown |
boolean |
| Returns | |
|---|---|
Notification.Builder |
|
See also:
setColor
Notification.Builder setColor (int argb)
Sets color.
| Parameters | |
|---|---|
argb |
int: The accent color to use |
| Returns | |
|---|---|
Notification.Builder |
The same Builder. |
setColorized
Notification.Builder setColorized (boolean colorize)
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 Notification.MediaStyle and Notification.DecoratedMediaCustomViewStyle notifications
that have a media session attached there is no such requirement.
| Parameters | |
|---|---|
colorize |
boolean |
| Returns | |
|---|---|
Notification.Builder |
|
setContent
Notification.Builder setContent (RemoteViews views)
Supply a custom RemoteViews to use instead of the platform template.
Use setCustomContentView(RemoteViews) instead.
| Parameters | |
|---|---|
views |
RemoteViews |
| Returns | |
|---|---|
Notification.Builder |
|
setContentInfo
Notification.Builder setContentInfo (CharSequence info)
This method was deprecated
in API level 24.
use setSubText(CharSequence) instead to set a text in the header.
For legacy apps targeting a version below 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).
| Parameters | |
|---|---|
info |
CharSequence |
| Returns | |
|---|---|
Notification.Builder |
|
setContentIntent
Notification.Builder setContentIntent (PendingIntent intent)
Supply a PendingIntent to be sent when the notification is clicked.
As of HONEYCOMB, if this field is unset and you
have specified a custom RemoteViews with setContent(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).
| Parameters | |
|---|---|
intent |
PendingIntent |
| Returns | |
|---|---|
Notification.Builder |
|
See also:
setContentText
Notification.Builder setContentText (CharSequence text)
Set the second line of text in the platform notification template.
| Parameters | |
|---|---|
text |
CharSequence |
| Returns | |
|---|---|
Notification.Builder |
|
setContentTitle
Notification.Builder setContentTitle (CharSequence title)
Set the first line of text in the platform notification template.
| Parameters | |
|---|---|
title |
CharSequence |
| Returns | |
|---|---|
Notification.Builder |
|
setCustomBigContentView
Notification.Builder setCustomBigContentView (RemoteViews contentView)
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.
| Parameters | |
|---|---|
contentView |
RemoteViews |
| Returns | |
|---|---|
Notification.Builder |
|
setCustomContentView
Notification.Builder setCustomContentView (RemoteViews contentView)
Supply custom RemoteViews to use instead of the platform template. This will override the layout that would otherwise be constructed by this Builder object.
| Parameters | |
|---|---|
contentView |
RemoteViews |
| Returns | |
|---|---|
Notification.Builder |
|
setCustomHeadsUpContentView
Notification.Builder setCustomHeadsUpContentView (RemoteViews contentView)
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.
| Parameters | |
|---|---|
contentView |
RemoteViews |
| Returns | |
|---|---|
Notification.Builder |
|
setDefaults
Notification.Builder setDefaults (int defaults)
This method was deprecated
in API level O.
use enableVibration(boolean) and
enableLights(boolean) and
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.
| Parameters | |
|---|---|
defaults |
int |
| Returns | |
|---|---|
Notification.Builder |
|
setDeleteIntent
Notification.Builder setDeleteIntent (PendingIntent intent)
Supply a PendingIntent to send when the notification is cleared explicitly by the user.
| Parameters | |
|---|---|
intent |
PendingIntent |
| Returns | |
|---|---|
Notification.Builder |
|
See also:
setExtras
Notification.Builder setExtras (Bundle extras)
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(Bundle) to merge in metadata instead.
| Parameters | |
|---|---|
extras |
Bundle |
| Returns | |
|---|---|
Notification.Builder |
|
See also:
setFullScreenIntent
Notification.Builder setFullScreenIntent (PendingIntent intent, boolean highPriority)
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.
| 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. |
| Returns | |
|---|---|
Notification.Builder |
|
See also:
setGroup
Notification.Builder setGroup (String groupKey)
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(boolean). A sort order can be specified for group members by using
setSortKey(String).
| Parameters | |
|---|---|
groupKey |
String: The group key of the group. |
| Returns | |
|---|---|
Notification.Builder |
this object for method chaining |
setGroupAlertBehavior
Notification.Builder setGroupAlertBehavior (int groupAlertBehavior)
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.
The default value is GROUP_ALERT_ALL.
| Parameters | |
|---|---|
groupAlertBehavior |
int Value is |
| Returns | |
|---|---|
Notification.Builder |
|
setGroupSummary
Notification.Builder setGroupSummary (boolean isGroupSummary)
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(String).
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. |
| Returns | |
|---|---|
Notification.Builder |
this object for method chaining |
setLargeIcon
Notification.Builder setLargeIcon (Bitmap b)
Add a large icon to the notification content view.
In the platform template, this image will be shown on the left of the notification view
in place of the small icon (which will be placed in a small
badge atop the large icon).
| Parameters | |
|---|---|
b |
Bitmap |
| Returns | |
|---|---|
Notification.Builder |
|
setLargeIcon
Notification.Builder setLargeIcon (Icon icon)
Add a large icon to the notification content view.
In the platform template, this image will be shown on the left of the notification view
in place of the small icon (which will be placed in a small
badge atop the large icon).
| Parameters | |
|---|---|
icon |
Icon |
| Returns | |
|---|---|
Notification.Builder |
|
setLights
Notification.Builder setLights (int argb, int onMs, int offMs)
This method was deprecated
in API level O.
use 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.
| Parameters | |
|---|---|
argb |
int |
onMs |
int |
offMs |
int |
| Returns | |
|---|---|
Notification.Builder |
|
setLocalOnly
Notification.Builder setLocalOnly (boolean localOnly)
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.
| Parameters | |
|---|---|
localOnly |
boolean |
| Returns | |
|---|---|
Notification.Builder |
|
setNumber
Notification.Builder setNumber (int number)
Sets the number of items this notification represents. May be displayed as a badge count for Launchers that support badging.
| Parameters | |
|---|---|
number |
int |
| Returns | |
|---|---|
Notification.Builder |
|
setOngoing
Notification.Builder setOngoing (boolean ongoing)
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).
| Parameters | |
|---|---|
ongoing |
boolean |
| Returns | |
|---|---|
Notification.Builder |
|
setOnlyAlertOnce
Notification.Builder setOnlyAlertOnce (boolean onlyAlertOnce)
Set this flag if you would only like the sound, vibrate and ticker to be played if the notification is not already showing.
| Parameters | |
|---|---|
onlyAlertOnce |
boolean |
| Returns | |
|---|---|
Notification.Builder |
|
See also:
setPriority
Notification.Builder setPriority (int pri)
This method was deprecated
in API level O.
use setImportance(int) instead.
Set the priority of this notification.
| Parameters | |
|---|---|
pri |
int |
| Returns | |
|---|---|
Notification.Builder |
|
See also:
setProgress
Notification.Builder setProgress (int max, int progress, boolean indeterminate)
Set the progress this notification represents.
The platform template will represent this using a ProgressBar.
| Parameters | |
|---|---|
max |
int |
progress |
int |
indeterminate |
boolean |
| Returns | |
|---|---|
Notification.Builder |
|
setPublicVersion
Notification.Builder setPublicVersion (Notification n)
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. |
| Returns | |
|---|---|
Notification.Builder |
The same Builder. |
setRemoteInputHistory
Notification.Builder setRemoteInputHistory (CharSequence[] text)
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.
| Parameters | |
|---|---|
text |
CharSequence |
| Returns | |
|---|---|
Notification.Builder |
|
setSettingsText
Notification.Builder setSettingsText (CharSequence text)
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.
| Returns | |
|---|---|
Notification.Builder |
|
setShortcutId
Notification.Builder setShortcutId (String shortcutId)
If this notification is duplicative of a Launcher shortcut, sets the
id of the shortcut, in case the Launcher wants to hide
the shortcut.
This field will be ignored by Launchers that don't support badging, don't show
notification content, or don't show shortcuts.
| Parameters | |
|---|---|
shortcutId |
String: the id of the shortcut this notification
supersedes
|
| Returns | |
|---|---|
Notification.Builder |
|
setShowWhen
Notification.Builder setShowWhen (boolean show)
Control whether the timestamp set with setWhen is shown
in the content view.
For apps targeting N and above, this defaults to
false. For earlier apps, the default is true.
| Parameters | |
|---|---|
show |
boolean |
| Returns | |
|---|---|
Notification.Builder |
|
setSmallIcon
Notification.Builder setSmallIcon (int icon, int level)
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. |
| Returns | |
|---|---|
Notification.Builder |
|
setSmallIcon
Notification.Builder setSmallIcon (int icon)
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. |
| Returns | |
|---|---|
Notification.Builder |
|
See also:
setSmallIcon
Notification.Builder setSmallIcon (Icon icon)
Set the small icon, which will be used to represent the notification in the
status bar and content view (unless overriden there by a
large icon).
| Parameters | |
|---|---|
icon |
Icon: An Icon object to use. |
| Returns | |
|---|---|
Notification.Builder |
|
See also:
setSortKey
Notification.Builder setSortKey (String sortKey)
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(String).
| Parameters | |
|---|---|
sortKey |
String |
| Returns | |
|---|---|
Notification.Builder |
|
See also:
setSound
Notification.Builder setSound (Uri sound, AudioAttributes audioAttributes)
This method was deprecated
in API level O.
use setSound(Uri, AudioAttributes) instead.
Set the sound to play, along with specific audio attributes to
use during playback.
| Parameters | |
|---|---|
sound |
Uri |
audioAttributes |
AudioAttributes |
| Returns | |
|---|---|
Notification.Builder |
|
See also:
setSound
Notification.Builder setSound (Uri sound)
This method was deprecated
in API level O.
use setSound(Uri, AudioAttributes) instead.
Set the sound to play.
It will be played using the default audio attributes
for notifications.
| Parameters | |
|---|---|
sound |
Uri |
| Returns | |
|---|---|
Notification.Builder |
|
setSound
Notification.Builder setSound (Uri sound, int streamType)
This method was deprecated
in API level 21.
use setSound(Uri, AudioAttributes).
Set the sound to play, along with a specific stream on which to play it.
See AudioManager for the STREAM_ constants.
| Parameters | |
|---|---|
sound |
Uri |
streamType |
int |
| Returns | |
|---|---|
Notification.Builder |
|
setStyle
Notification.Builder setStyle (Notification.Style style)
Add a rich notification style to be applied at build time.
| Parameters | |
|---|---|
style |
Notification.Style: Object responsible for modifying the notification style.
|
| Returns | |
|---|---|
Notification.Builder |
|
setSubText
Notification.Builder setSubText (CharSequence text)
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 N this information is displayed in the
notification header area.
On Android versions before 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.
| Parameters | |
|---|---|
text |
CharSequence |
| Returns | |
|---|---|
Notification.Builder |
|
setTicker
Notification.Builder setTicker (CharSequence tickerText, RemoteViews views)
Obsolete version of setTicker(CharSequence).
| Parameters | |
|---|---|
tickerText |
CharSequence |
views |
RemoteViews |
| Returns | |
|---|---|
Notification.Builder |
|
setTicker
Notification.Builder setTicker (CharSequence tickerText)
Set the "ticker" text which is sent to accessibility services.
| Parameters | |
|---|---|
tickerText |
CharSequence |
| Returns | |
|---|---|
Notification.Builder |
|
See also:
setTimeoutAfter
Notification.Builder setTimeoutAfter (long durationMs)
Specifies a duration in milliseconds after which this notification should be canceled, if it is not already canceled.
| Parameters | |
|---|---|
durationMs |
long |
| Returns | |
|---|---|
Notification.Builder |
|
setUsesChronometer
Notification.Builder setUsesChronometer (boolean b)
Show the 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).
| Parameters | |
|---|---|
b |
boolean |
| Returns | |
|---|---|
Notification.Builder |
|
setVibrate
Notification.Builder setVibrate (long[] pattern)
This method was deprecated
in API level O.
use setVibrationPattern(long[]) instead.
Set the vibration pattern to use.
See 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.
| Parameters | |
|---|---|
pattern |
long |
| Returns | |
|---|---|
Notification.Builder |
|
See also:
setVisibility
Notification.Builder setVisibility (int visibility)
Specify the value of visibility.
| Parameters | |
|---|---|
visibility |
int Value is |
| Returns | |
|---|---|
Notification.Builder |
The same Builder. |
setWhen
Notification.Builder setWhen (long when)
Add a timestamp pertaining to the notification (usually the time the event occurred).
For apps targeting N and above, this time is not
shown anymore by default and must be opted into by using
setShowWhen(boolean)
| Parameters | |
|---|---|
when |
long |
| Returns | |
|---|---|
Notification.Builder |
|
See also:
Interfaces
- ActionBar.OnMenuVisibilityListener
- ActionBar.OnNavigationListener
- ActionBar.TabListener
- AlarmManager.OnAlarmListener
- Application.ActivityLifecycleCallbacks
- Application.OnProvideAssistDataListener
- AppOpsManager.OnOpChangedListener
- DatePickerDialog.OnDateSetListener
- FragmentBreadCrumbs.OnBreadCrumbClickListener
- FragmentManager.BackStackEntry
- FragmentManager.OnBackStackChangedListener
- KeyguardManager.OnKeyguardExitResult
- LoaderManager.LoaderCallbacks
- Notification.Action.Extender
- Notification.Extender
- PendingIntent.OnFinished
- SearchManager.OnCancelListener
- SearchManager.OnDismissListener
- SharedElementCallback.OnSharedElementsReadyListener
- TimePickerDialog.OnTimeSetListener
- UiAutomation.AccessibilityEventFilter
- UiAutomation.OnAccessibilityEventListener
Classes
- ActionBar
- ActionBar.LayoutParams
- ActionBar.Tab
- Activity
- ActivityGroup
- ActivityManager
- ActivityManager.AppTask
- ActivityManager.MemoryInfo
- ActivityManager.ProcessErrorStateInfo
- ActivityManager.RecentTaskInfo
- ActivityManager.RunningAppProcessInfo
- ActivityManager.RunningServiceInfo
- ActivityManager.RunningTaskInfo
- ActivityManager.TaskDescription
- ActivityOptions
- AlarmManager
- AlarmManager.AlarmClockInfo
- AlertDialog
- AlertDialog.Builder
- AliasActivity
- Application
- ApplicationErrorReport
- ApplicationErrorReport.AnrInfo
- ApplicationErrorReport.BatteryInfo
- ApplicationErrorReport.CrashInfo
- ApplicationErrorReport.RunningServiceInfo
- AppOpsManager
- AutomaticZenRule
- DatePickerDialog
- Dialog
- DialogFragment
- DownloadManager
- DownloadManager.Query
- DownloadManager.Request
- ExpandableListActivity
- Fragment
- Fragment.SavedState
- FragmentBreadCrumbs
- FragmentContainer
- FragmentController
- FragmentHostCallback
- FragmentManager
- FragmentManager.FragmentLifecycleCallbacks
- FragmentManagerNonConfig
- FragmentTransaction
- Instrumentation
- Instrumentation.ActivityMonitor
- Instrumentation.ActivityResult
- IntentService
- KeyguardManager
- KeyguardManager.KeyguardDismissCallback
- KeyguardManager.KeyguardLock
- LauncherActivity
- LauncherActivity.IconResizer
- LauncherActivity.ListItem
- ListActivity
- ListFragment
- LoaderManager
- LocalActivityManager
- MediaRouteActionProvider
- MediaRouteButton
- NativeActivity
- Notification
- Notification.Action
- Notification.Action.Builder
- Notification.Action.WearableExtender
- Notification.BigPictureStyle
- Notification.BigTextStyle
- Notification.Builder
- Notification.CarExtender
- Notification.CarExtender.Builder
- Notification.CarExtender.UnreadConversation
- Notification.DecoratedCustomViewStyle
- Notification.DecoratedMediaCustomViewStyle
- Notification.InboxStyle
- Notification.MediaStyle
- Notification.MessagingStyle
- Notification.MessagingStyle.Message
- Notification.Style
- Notification.WearableExtender
- NotificationChannel
- NotificationChannelGroup
- NotificationManager
- NotificationManager.Policy
- PendingIntent
- PictureInPictureParams
- PictureInPictureParams.Builder
- Presentation
- ProgressDialog
- RemoteAction
- RemoteInput
- RemoteInput.Builder
- SearchableInfo
- SearchManager
- Service
- SharedElementCallback
- TabActivity
- TaskStackBuilder
- TimePickerDialog
- UiAutomation
- UiModeManager
- VoiceInteractor
- VoiceInteractor.AbortVoiceRequest
- VoiceInteractor.CommandRequest
- VoiceInteractor.CompleteVoiceRequest
- VoiceInteractor.ConfirmationRequest
- VoiceInteractor.PickOptionRequest
- VoiceInteractor.PickOptionRequest.Option
- VoiceInteractor.Prompt
- VoiceInteractor.Request
- WallpaperInfo
- WallpaperManager
Exceptions