android-Notification.Builder
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) Constructs a new Builder with the defaults:
|
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 |
staticNotification.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 | setCategory(String category) Set the notification category. |
Notification.Builder | setChronometerCountDown(boolean countDown) Sets the Chronometer to count down instead of counting up. |
Notification.Builder | setColor(int argb) Sets |
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) Set which notification properties will be inherited from system defaults. |
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 | 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) Set the desired color for the indicator LED on the device, as well as the blink duty cycle (specified in milliseconds). |
Notification.Builder | setLocalOnly(boolean localOnly) Set whether or not this notification should not bridge to other devices. |
Notification.Builder | setNumber(int number) This method was deprecated in API level 24. this number is not shown anywhere anymore |
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) Set the priority of this notification. |
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 | 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) Set the sound to play, along with specific |
Notification.Builder | setSound(Uri sound) Set the sound to play. |
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 | setUsesChronometer(boolean b) Show the |
Notification.Builder | setVibrate(long[] pattern) Set the vibration pattern to 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 | |
---|---|
From class java.lang.Object |
Public constructors
Notification.Builder
Added in API level 11Notification.Builder (Context context)
Constructs a new Builder with the defaults:
priority | PRIORITY_DEFAULT |
---|---|
when | now (currentTimeMillis() ) |
audio stream | STREAM_DEFAULT |
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. |
Public methods
addAction
Added in API level 16Notification.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
Added in API level 20Notification.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
Added in API level 20Notification.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:
extras
addPerson
Added in API level 21Notification.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, and 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:
EXTRA_PEOPLE
build
Added in API level 16Notification build ()
Combine all of the options that have been set and return a new Notification
object.
Returns | |
---|---|
Notification |
createBigContentView
Added in API level 24RemoteViews createBigContentView ()
Construct a RemoteViews for the final big notification layout.
Returns | |
---|---|
RemoteViews |
createContentView
Added in API level 24RemoteViews 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
Added in API level 24RemoteViews createHeadsUpContentView ()
Construct a RemoteViews for the final heads-up notification layout.
Returns | |
---|---|
RemoteViews |
extend
Added in API level 20Notification.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
Added in API level 20Bundle 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:
extras
getNotification
Added in API level 11Notification getNotification ()
This method was deprecated in API level 16.
Use build()
instead.
Returns | |
---|---|
Notification |
recoverBuilder
Added in API level 24Notification.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
Added in API level 24Notification.Builder setActions (Action... actions)
Alter the complete list of actions attached to this notification.
Returns | |
---|---|
Notification.Builder |
See also:
addAction(Action)
setAutoCancel
Added in API level 11Notification.Builder setAutoCancel (boolean autoCancel)
Make this notification automatically dismissed when the user touches it. The PendingIntent set with setDeleteIntent(PendingIntent)
will be sent when this happens.
Parameters | |
---|---|
autoCancel | boolean |
Returns | |
---|---|
Notification.Builder |
See also:
FLAG_AUTO_CANCEL
setCategory
Added in API level 21Notification.Builder setCategory (String category)
Set the notification category.
Parameters | |
---|---|
category | String |
Returns | |
---|---|
Notification.Builder |
See also:
category
setChronometerCountDown
Added in API level 24Notification.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:
setUsesChronometer(boolean)
setColor
Added in API level 21Notification.Builder setColor (int argb)
Sets color
.
Parameters | |
---|---|
argb | int : The accent color to use |
Returns | |
---|---|
Notification.Builder | The same Builder. |
setContent
Added in API level 11Notification.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
Added in API level 11Notification.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
Added in API level 11Notification.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:
Notification.contentIntent
setContentText
Added in API level 11Notification.Builder setContentText (CharSequence text)
Set the second line of text in the platform notification template.
Parameters | |
---|---|
text | CharSequence |
Returns | |
---|---|
Notification.Builder |
setContentTitle
Added in API level 11Notification.Builder setContentTitle (CharSequence title)
Set the first line of text in the platform notification template.
Parameters | |
---|---|
title | CharSequence |
Returns | |
---|---|
Notification.Builder |
setCustomBigContentView
Added in API level 24Notification.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
Added in API level 24Notification.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
Added in API level 24Notification.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
Added in API level 11Notification.Builder setDefaults (int defaults)
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
Added in API level 11Notification.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:
deleteIntent
setExtras
Added in API level 19Notification.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:
extras
setFullScreenIntent
Added in API level 11Notification.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'simmediate 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:
fullScreenIntent
setGroup
Added in API level 20Notification.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 usingsetSortKey(String)
.
Parameters | |
---|---|
groupKey | String : The group key of the group. |
Returns | |
---|---|
Notification.Builder | this object for method chaining |
setGroupSummary
Added in API level 20Notification.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. Requires a group key also be set using setGroup(String)
.
Parameters | |
---|---|
isGroupSummary | boolean : Whether this notification should be a group summary. |
Returns | |
---|---|
Notification.Builder | this object for method chaining |
setLargeIcon
Added in API level 11Notification.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 thesmall icon
(which will be placed in a small badge atop the large icon).
Parameters | |
---|---|
b | Bitmap |
Returns | |
---|---|
Notification.Builder |
setLargeIcon
Added in API level 23Notification.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 thesmall icon
(which will be placed in a small badge atop the large icon).
Parameters | |
---|---|
icon | Icon |
Returns | |
---|---|
Notification.Builder |
setLights
Added in API level 11Notification.Builder setLights (int argb, int onMs, int offMs)
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 |
See also:
ledARGB
ledOnMS
ledOffMS
setLocalOnly
Added in API level 20Notification.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
Added in API level 11Notification.Builder setNumber (int number)
This method was deprecated in API level 24.
this number is not shown anywhere anymore
Set the large number at the right-hand side of the notification. This is equivalent to setContentInfo, although it might show the number in a different font size for readability.
Parameters | |
---|---|
number | int |
Returns | |
---|---|
Notification.Builder |
setOngoing
Added in API level 11Notification.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 |
See also:
FLAG_ONGOING_EVENT
ERROR(/Service#setForeground(boolean))
setOnlyAlertOnce
Added in API level 11Notification.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:
FLAG_ONLY_ALERT_ONCE
setPriority
Added in API level 16Notification.Builder setPriority (int pri)
Set the priority of this notification.
Parameters | |
---|---|
pri | int |
Returns | |
---|---|
Notification.Builder |
See also:
priority
setProgress
Added in API level 14Notification.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
Added in API level 21Notification.Builder setPublicVersion (Notification n)
Supply a replacement Notification whose contents should be shown in insecure contexts (i.e. atop the secure lockscreen). See visibility
andVISIBILITY_PUBLIC
.
Parameters | |
---|---|
n | Notification : A replacement notification, presumably with some or all info redacted. |
Returns | |
---|---|
Notification.Builder | The same Builder. |
setRemoteInputHistory
Added in API level 24Notification.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 |
setShowWhen
Added in API level 17Notification.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
Added in API level 11Notification.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 |
See also:
icon
iconLevel
setSmallIcon
Added in API level 11Notification.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:
icon
setSmallIcon
Added in API level 23Notification.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:
icon
setSortKey
Added in API level 20Notification.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:
compareTo(String)
setSound
Added in API level 21Notification.Builder setSound (Uri sound, AudioAttributes audioAttributes)
Set the sound to play, along with specific audio attributes
to use during playback.
A notification that is noisy is more likely to be presented as a heads-up notification.
Parameters | |
---|---|
sound | Uri |
audioAttributes | AudioAttributes |
Returns | |
---|---|
Notification.Builder |
See also:
sound
setSound
Added in API level 11Notification.Builder setSound (Uri sound)
Set the sound to play. It will be played using the default audio attributes
for notifications.
A notification that is noisy is more likely to be presented as a heads-up notification.
Parameters | |
---|---|
sound | Uri |
Returns | |
---|---|
Notification.Builder |
See also:
sound
setSound
Added in API level 11Notification.Builder setSound (Uri sound, int streamType)
This method was deprecated in API level 21.
use setSound(Uri, AudioAttributes)
instead.
Set the sound to play, along with a specific stream on which to play it. See AudioManager
for the STREAM_
constants.
A notification that is noisy is more likely to be presented as a heads-up notification.
Parameters | |
---|---|
sound | Uri |
streamType | int |
Returns | |
---|---|
Notification.Builder |
See also:
sound
setStyle
Added in API level 16Notification.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
Added in API level 16Notification.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
Added in API level 11Notification.Builder setTicker (CharSequence tickerText, RemoteViews views)
Obsolete version of setTicker(CharSequence)
.
Parameters | |
---|---|
tickerText | CharSequence |
views | RemoteViews |
Returns | |
---|---|
Notification.Builder |
setTicker
Added in API level 11Notification.Builder setTicker (CharSequence tickerText)
Set the "ticker" text which is sent to accessibility services.
Parameters | |
---|---|
tickerText | CharSequence |
Returns | |
---|---|
Notification.Builder |
See also:
tickerText
setUsesChronometer
Added in API level 16Notification.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 |
See also:
Chronometer
when
setChronometerCountDown(boolean)
setVibrate
Added in API level 11Notification.Builder setVibrate (long[] pattern)
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:
vibrate
setVisibility
Added in API level 21Notification.Builder setVisibility (int visibility)
Specify the value of visibility
.
Parameters | |
---|---|
visibility | int : One of VISIBILITY_PRIVATE (the default), VISIBILITY_SECRET , or VISIBILITY_PUBLIC . |
Returns | |
---|---|
Notification.Builder | The same Builder. |
setWhen
Added in API level 11Notification.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 |
更多相关文章
- 代码中设置drawableleft
- android 3.0 隐藏 系统标题栏
- Android开发中activity切换动画的实现
- Android(安卓)学习 笔记_05. 文件下载
- Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
- 技术博客汇总
- android 2.3 wifi (一)
- AndRoid Notification的清空和修改
- Android中的Chronometer