# Print output for @column tags ?>
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();
Public constructors | |
---|---|
Builder(Context context, String channelId)
Constructs a new Builder with the defaults: |
|
Builder(Context context)
This constructor is deprecated.
use |
Public methods | |
---|---|
Notification.Builder
|
addAction(int icon, CharSequence title, PendingIntent intent)
This method is deprecated.
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)
This method is deprecated.
use |
Notification.Builder
|
addPerson(Person person)
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 is deprecated.
Use |
Notification.Style
|
getStyle()
Returns the style set by |
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
|
setAllowSystemGeneratedContextualActions(boolean allowed)
Determines whether the platform can generate contextual actions for a 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
|
setBubbleMetadata(Notification.BubbleMetadata data)
Sets the |
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 is deprecated.
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 is deprecated.
use |
Notification.Builder
|
setDeleteIntent(PendingIntent intent)
Supply a |
Notification.Builder
|
setExtras(Bundle extras)
Set metadata for this notification. |
Notification.Builder
|
setFlag(int mask, boolean value)
Set the value for a notification flag |
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 is deprecated.
use |
Notification.Builder
|
setLocalOnly(boolean localOnly)
Set whether or not this notification should not bridge to other devices. |
Notification.Builder
|
setLocusId(LocusId locusId)
Sets the |
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 is deprecated.
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)
From Android 11, messaging notifications (those that use |
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 overridden 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 is deprecated.
use |
Notification.Builder
|
setSound(Uri sound)
This method is deprecated.
use |
Notification.Builder
|
setSound(Uri sound, int streamType)
This method is deprecated.
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 is deprecated.
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 | |
---|---|
public 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 NotificationManager#createNotificationChannel . |
public Builder (Context context)
This constructor is deprecated.
use Builder(android.content.Context, java.lang.String)
instead. All posted Notifications must specify a NotificationChannel Id.
Parameters | |
---|---|
context |
Context |
public Notification.Builder addAction (int icon, CharSequence title, PendingIntent intent)
This method is deprecated.
Use addAction(android.app.Notification.Action)
instead.
Add an action to this notification. Actions are typically displayed by the system as a button adjacent to the notification content.
Every action must have an icon (32dp square and matching the
Holo
Dark action bar visual style), a textual label, and a PendingIntent
.
A notification in its expanded form can display up to 3 actions, from left to right in
the order they were added. Actions will not be displayed when the notification is
collapsed, however, so be sure that any essential functions may be accessed by the user
in some other way (for example, in the Activity pointed to by Notification.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 |
public 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 Notification.contentIntent
).
Parameters | |
---|---|
action |
Notification.Action : The action to add. |
Returns | |
---|---|
Notification.Builder |
This value cannot be null . |
public 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 |
This value cannot be null . |
See also:
public Notification.Builder addPerson (String uri)
This method is deprecated.
use addPerson(android.app.Person)
Add a person that is relevant to this notification.
Depending on user preferences, this annotation may allow the notification to pass
through interruption filters, if this notification is of category Notification.CATEGORY_CALL
or Notification.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
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 ContactsContract.PhoneLookup
.
It is also possible to provide a URI with the schema name:
in order to uniquely
identify a person without an entry in the contacts database.
Parameters | |
---|---|
uri |
String : A URI for the person. |
Returns | |
---|---|
Notification.Builder |
See also:
public Notification.Builder addPerson (Person person)
Add a person that is relevant to this notification.
Depending on user preferences, this annotation may allow the notification to pass
through interruption filters, if this notification is of category Notification.CATEGORY_CALL
or Notification.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. |
Returns | |
---|---|
Notification.Builder |
This value cannot be null . |
See also:
public Notification build ()
Combine all of the options that have been set and return a new Notification
object.
If this notification has BubbleMetadata
attached that was created with
a shortcutId a check will be performed to ensure the shortcutId supplied to bubble
metadata matches the shortcutId set on the notification builder, if one was set.
If the shortcutId's were specified but do not match, an exception is thrown here.
Returns | |
---|---|
Notification |
This value cannot be null . |
public RemoteViews createBigContentView ()
Construct a RemoteViews for the final big notification layout.
Returns | |
---|---|
RemoteViews |
public 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 |
public RemoteViews createHeadsUpContentView ()
Construct a RemoteViews for the final heads-up notification layout.
Returns | |
---|---|
RemoteViews |
public 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 |
This value cannot be null . |
public 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:
public Notification getNotification ()
This method is deprecated.
Use build()
instead.
Returns | |
---|---|
Notification |
public Notification.Style getStyle ()
Returns the style set by setStyle(android.app.Notification.Style)
.
Returns | |
---|---|
Notification.Style |
public static 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 |
This value cannot be null . |
public Notification.Builder setActions (Action... actions)
Alter the complete list of actions attached to this notification.
Returns | |
---|---|
Notification.Builder |
This value cannot be null . |
See also:
public Notification.Builder setAllowSystemGeneratedContextualActions (boolean allowed)
Determines whether the platform can generate contextual actions for a notification. By default this is true.
Parameters | |
---|---|
allowed |
boolean |
Returns | |
---|---|
Notification.Builder |
This value cannot be null . |
public Notification.Builder setAutoCancel (boolean autoCancel)
Make this notification automatically dismissed when the user touches it.
Parameters | |
---|---|
autoCancel |
boolean |
Returns | |
---|---|
Notification.Builder |
This value cannot be null . |
See also:
public Notification.Builder setBadgeIconType (int icon)
Sets which icon to display as a badge for this notification.
Must be one of Notification.BADGE_ICON_NONE
, Notification.BADGE_ICON_SMALL
,
Notification.BADGE_ICON_LARGE
.
Note: This value might be ignored, for launchers that don't support badge icons.
Parameters | |
---|---|
icon |
int |
Returns | |
---|---|
Notification.Builder |
This value cannot be null . |
public Notification.Builder setBubbleMetadata (Notification.BubbleMetadata data)
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 NotificationChannel#canBubble()
.
Notifications allowed to bubble that have valid bubble metadata will display in collapsed state outside of the notification shade on unlocked devices. When a user interacts with the collapsed state, the bubble intent will be invoked and displayed.
Parameters | |
---|---|
data |
Notification.BubbleMetadata : This value may be null . |
Returns | |
---|---|
Notification.Builder |
This value cannot be null . |
public Notification.Builder setCategory (String category)
Set the notification category.
Parameters | |
---|---|
category |
String |
Returns | |
---|---|
Notification.Builder |
This value cannot be null . |
See also:
public Notification.Builder setChannelId (String channelId)
Specifies the channel the notification should be delivered on.
Parameters | |
---|---|
channelId |
String |
Returns | |
---|---|
Notification.Builder |
This value cannot be null . |
public 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 |
This value cannot be null . |
See also:
public Notification.Builder setColor (int argb)
Sets Notification#color
.
Parameters | |
---|---|
argb |
int : The accent color to use |
Returns | |
---|---|
Notification.Builder |
The same Builder.
This value cannot be null . |
public 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 MediaStyle
and DecoratedMediaCustomViewStyle
notifications
that have a media session attached there is no such requirement.
Parameters | |
---|---|
colorize |
boolean |
Returns | |
---|---|
Notification.Builder |
This value cannot be null . |
public Notification.Builder setContent (RemoteViews views)
Supply a custom RemoteViews to use instead of the platform template.
Use setCustomContentView(android.widget.RemoteViews)
instead.
Parameters | |
---|---|
views |
RemoteViews |
Returns | |
---|---|
Notification.Builder |
public Notification.Builder setContentInfo (CharSequence info)
This method is deprecated.
use setSubText(java.lang.CharSequence)
instead to set a text in the header.
For legacy apps targeting a version below Build.VERSION_CODES.N
this
field will still show up, but the subtext will take precedence.
A small piece of additional information pertaining to this notification. The platform template will draw this on the last line of the notification, at the far right (to the right of a smallIcon if it has been placed there).
Parameters | |
---|---|
info |
CharSequence |
Returns | |
---|---|
Notification.Builder |
public Notification.Builder setContentIntent (PendingIntent intent)
Supply a PendingIntent
to be sent when the notification is clicked.
As of Build.VERSION_CODES.HONEYCOMB
, if this field is unset and you
have specified a custom RemoteViews with setContent(android.widget.RemoteViews)
, you can use
RemoteViews#setOnClickPendingIntent
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 |
This value cannot be null . |
See also:
public Notification.Builder setContentText (CharSequence text)
Set the second line of text in the platform notification template.
Parameters | |
---|---|
text |
CharSequence |
Returns | |
---|---|
Notification.Builder |
This value cannot be null . |
public Notification.Builder setContentTitle (CharSequence title)
Set the first line of text in the platform notification template.
Parameters | |
---|---|
title |
CharSequence |
Returns | |
---|---|
Notification.Builder |
This value cannot be null . |
public 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 |
This value cannot be null . |
public 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 |
This value cannot be null . |
public 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 |
This value cannot be null . |
public Notification.Builder setDefaults (int defaults)
This method is deprecated.
use NotificationChannel#enableVibration(boolean)
and
NotificationChannel#enableLights(boolean)
and
NotificationChannel#setSound(Uri, AudioAttributes)
instead.
Set which notification properties will be inherited from system defaults.
The value should be one or more of the following fields combined with
bitwise-or:
Notification.DEFAULT_SOUND
, Notification.DEFAULT_VIBRATE
, Notification.DEFAULT_LIGHTS
.
For all default values, use Notification.DEFAULT_ALL
.
Parameters | |
---|---|
defaults |
int |
Returns | |
---|---|
Notification.Builder |
public 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 |
This value cannot be null . |
See also:
public 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 |
This value cannot be null . |
See also:
public Notification.Builder setFlag (int mask, boolean value)
Set the value for a notification flag
Parameters | |
---|---|
mask |
int : Bit mask of the flag
Value is Notification.FLAG_SHOW_LIGHTS , Notification.FLAG_ONGOING_EVENT , Notification.FLAG_INSISTENT , Notification.FLAG_ONLY_ALERT_ONCE , Notification.FLAG_AUTO_CANCEL , Notification.FLAG_NO_CLEAR , Notification.FLAG_FOREGROUND_SERVICE , Notification.FLAG_HIGH_PRIORITY , Notification.FLAG_LOCAL_ONLY , Notification.FLAG_GROUP_SUMMARY , android.app.Notification.FLAG_AUTOGROUP_SUMMARY, or Notification.FLAG_BUBBLE |
value |
boolean : Status (on/off) of the flag |
Returns | |
---|---|
Notification.Builder |
The same Builder.
This value cannot be null . |
public 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.
Apps targeting Build.VERSION_CODES#Q
and above will have to request
a permission (Manifest.permission.USE_FULL_SCREEN_INTENT
) in order to
use full screen intents.
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 |
This value cannot be null . |
See also:
public 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
This value cannot be null . |
public 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
. 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 Notification.GROUP_ALERT_SUMMARY
.
The default value is Notification.GROUP_ALERT_ALL
.
Parameters | |
---|---|
groupAlertBehavior |
int : Value is Notification.GROUP_ALERT_ALL , Notification.GROUP_ALERT_CHILDREN , or Notification.GROUP_ALERT_SUMMARY |
Returns | |
---|---|
Notification.Builder |
This value cannot be null . |
public 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
This value cannot be null . |
public 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 |
This value cannot be null . |
public 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 |
This value cannot be null . |
public Notification.Builder setLights (int argb, int onMs, int offMs)
This method is deprecated.
use NotificationChannel#enableLights(boolean)
instead.
Set the desired color for the indicator LED on the device, as well as the blink duty cycle (specified in milliseconds). Not all devices will honor all (or even any) of these values.
Parameters | |
---|---|
argb |
int |
onMs |
int |
offMs |
int |
Returns | |
---|---|
Notification.Builder |
public 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 |
This value cannot be null . |
public Notification.Builder setLocusId (LocusId locusId)
Sets the LocusId
associated with this notification.
This method should be called when the LocusId
is used in other places (such
as ShortcutInfo
and ContentCaptureContext
) so the device's intelligence
services can correlate them.
Parameters | |
---|---|
locusId |
LocusId : This value may be null . |
Returns | |
---|---|
Notification.Builder |
This value cannot be null . |
public 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 |
This value cannot be null . |
public 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 |
This value cannot be null . |
See also:
public 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 |
This value cannot be null . |
See also:
public Notification.Builder setPriority (int pri)
This method is deprecated.
use NotificationChannel#setImportance(int)
instead.
Set the priority of this notification.
Parameters | |
---|---|
pri |
int : Value is Notification.PRIORITY_DEFAULT , Notification.PRIORITY_LOW , Notification.PRIORITY_MIN , Notification.PRIORITY_HIGH , or Notification.PRIORITY_MAX |
Returns | |
---|---|
Notification.Builder |
See also:
public 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 |
This value cannot be null . |
public Notification.Builder setPublicVersion (Notification n)
Supply a replacement Notification whose contents should be shown in insecure contexts
(i.e. atop the secure lockscreen). See Notification.visibility
and Notification.VISIBILITY_PUBLIC
.
Parameters | |
---|---|
n |
Notification : A replacement notification, presumably with some or all info redacted. |
Returns | |
---|---|
Notification.Builder |
The same Builder.
This value cannot be null . |
public 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 |
This value cannot be null . |
public 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 Style
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 Notification.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 |
This value cannot be null . |
public Notification.Builder setShortcutId (String shortcutId)
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:
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 ShortcutInfo#getId() of the shortcut this notification
is linked to |
Returns | |
---|---|
Notification.Builder |
This value cannot be null . |
public Notification.Builder setShowWhen (boolean show)
Control whether the timestamp set with setWhen
is shown
in the content view.
For apps targeting Build.VERSION_CODES.N
and above, this defaults to
false
. For earlier apps, the default is true
.
Parameters | |
---|---|
show |
boolean |
Returns | |
---|---|
Notification.Builder |
This value cannot be null . |
public 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 |
This value cannot be null . |
See also:
public 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 |
This value cannot be null . |
See also:
public 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 overridden there by a
large icon
).
Parameters | |
---|---|
icon |
Icon : An Icon object to use. |
Returns | |
---|---|
Notification.Builder |
This value cannot be null . |
See also:
public 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 |
This value cannot be null . |
See also:
public Notification.Builder setSound (Uri sound, AudioAttributes audioAttributes)
This method is deprecated.
use NotificationChannel#setSound(Uri, AudioAttributes)
instead.
Set the sound to play, along with specific AudioAttributes
to
use during playback.
Parameters | |
---|---|
sound |
Uri |
audioAttributes |
AudioAttributes |
Returns | |
---|---|
Notification.Builder |
See also:
public Notification.Builder setSound (Uri sound)
This method is deprecated.
use NotificationChannel#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 |
public Notification.Builder setSound (Uri sound, int streamType)
This method is deprecated.
use NotificationChannel#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 |
public 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 |
This value cannot be null . |
public 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 Build.VERSION_CODES.N
this information is displayed in the
notification header area.
On Android versions before 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.
Parameters | |
---|---|
text |
CharSequence |
Returns | |
---|---|
Notification.Builder |
This value cannot be null . |
public Notification.Builder setTicker (CharSequence tickerText, RemoteViews views)
Obsolete version of setTicker(java.lang.CharSequence)
.
Parameters | |
---|---|
tickerText |
CharSequence |
views |
RemoteViews |
Returns | |
---|---|
Notification.Builder |
public Notification.Builder setTicker (CharSequence tickerText)
Set the "ticker" text which is sent to accessibility services.
Parameters | |
---|---|
tickerText |
CharSequence |
Returns | |
---|---|
Notification.Builder |
This value cannot be null . |
See also:
public 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 |
This value cannot be null . |
public Notification.Builder setUsesChronometer (boolean b)
Show the Notification#when
field as a stopwatch.
Instead of presenting when
as a timestamp, the notification will show an
automatically updating display of the minutes and seconds since when
.
Useful when showing an elapsed time (like an ongoing phone call).
The counter can also be set to count down to when
when using
setChronometerCountDown(boolean)
.
Parameters | |
---|---|
b |
boolean |
Returns | |
---|---|
Notification.Builder |
This value cannot be null . |
public Notification.Builder setVibrate (long[] pattern)
This method is deprecated.
use NotificationChannel#setVibrationPattern(long[])
instead.
Set the vibration pattern to use.
See Vibrator.vibrate(long[], int)
for a discussion of the
pattern
parameter.
A notification that vibrates is more likely to be presented as a heads-up notification.
Parameters | |
---|---|
pattern |
long |
Returns | |
---|---|
Notification.Builder |
See also:
public Notification.Builder setVisibility (int visibility)
Specify the value of Notification.visibility
.
Parameters | |
---|---|
visibility |
int : Value is Notification.VISIBILITY_PUBLIC , Notification.VISIBILITY_PRIVATE , or Notification.VISIBILITY_SECRET |
Returns | |
---|---|
Notification.Builder |
The same Builder.
This value cannot be null . |
public Notification.Builder setWhen (long when)
Add a timestamp pertaining to the notification (usually the time the event occurred).
For apps targeting Build.VERSION_CODES.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 |
This value cannot be null . |
See also: