public static class

Notification.Builder

extends Object
java.lang.Object
   ↳ android.app.Notification.Builder

Class Overview

Builder class for Notification objects. Allows easier control over all the flags, as well as help constructing the typical notification layouts.

Summary

Public Constructors
Notification.Builder(Context context)
Constructor.
Public Methods
Notification getNotification()
Combine all of the options that have been set and return a new Notification object.
Notification.Builder setAutoCancel(boolean autoCancel)
Setting this flag will make it so the notification is automatically canceled when the user clicks it in the panel.
Notification.Builder setContent(RemoteViews views)
Supply a custom RemoteViews to use instead of the standard one.
Notification.Builder setContentInfo(CharSequence info)
Set the large text at the right-hand side of the notification.
Notification.Builder setContentIntent(PendingIntent intent)
Supply a PendingIntent to send when the notification is clicked.
Notification.Builder setContentText(CharSequence text)
Set the text (second row) of the notification, in a standard notification.
Notification.Builder setContentTitle(CharSequence title)
Set the title (first row) of the notification, in a standard notification.
Notification.Builder setDefaults(int defaults)
Set the default notification options that will be used.
Notification.Builder setDeleteIntent(PendingIntent intent)
Supply a PendingIntent to send when the notification is cleared by the user directly from the notification panel.
Notification.Builder setFullScreenIntent(PendingIntent intent, boolean highPriority)
An intent to launch instead of posting the notification to the status bar.
Notification.Builder setLargeIcon(Bitmap icon)
Set the large icon that is shown in the ticker and notification.
Notification.Builder setLights(int argb, int onMs, int offMs)
Set the argb value that you would like the LED on the device to blnk, as well as the rate.
Notification.Builder setNumber(int number)
Set the large number at the right-hand side of the notification.
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 setProgress(int max, int progress, boolean indeterminate)
Set the progress this notification represents, which may be represented as a ProgressBar.
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.
Notification.Builder setSmallIcon(int icon)
Set the small icon to use in the notification layouts.
Notification.Builder setSound(Uri sound)
Set the sound to play.
Notification.Builder setSound(Uri sound, int streamType)
Set the sound to play.
Notification.Builder setTicker(CharSequence tickerText, RemoteViews views)
Set the text that is displayed in the status bar when the notification first arrives, and also a RemoteViews object that may be displayed instead on some devices.
Notification.Builder setTicker(CharSequence tickerText)
Set the text that is displayed in the status bar when the notification first arrives.
Notification.Builder setVibrate(long[] pattern)
Set the vibration pattern to use.
Notification.Builder setWhen(long when)
Set the time that the event occurred.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public Notification.Builder (Context context)

Since: API Level 11

Constructor. Automatically sets the when field to System.currentTimeMllis() and the audio stream to the STREAM_DEFAULT.

Parameters
context A Context that will be used to construct the RemoteViews. The Context will not be held past the lifetime of this Builder object.

Public Methods

public Notification getNotification ()

Since: API Level 11

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

public Notification.Builder setAutoCancel (boolean autoCancel)

Since: API Level 11

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

public Notification.Builder setContent (RemoteViews views)

Since: API Level 11

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

public Notification.Builder setContentInfo (CharSequence info)

Since: API Level 11

Set the large text at the right-hand side of the notification.

public Notification.Builder setContentIntent (PendingIntent intent)

Since: API Level 11

Supply a PendingIntent to send when the notification is clicked. If you do not supply an intent, you can now add PendingIntents to individual views to be launched when clicked by calling RemoteViews.setOnClickPendingIntent(int,PendingIntent).

public Notification.Builder setContentText (CharSequence text)

Since: API Level 11

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

public Notification.Builder setContentTitle (CharSequence title)

Since: API Level 11

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

public Notification.Builder setDefaults (int defaults)

Since: API Level 11

Set the default notification options that will be used.

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.

public Notification.Builder setDeleteIntent (PendingIntent intent)

Since: API Level 11

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

public Notification.Builder setFullScreenIntent (PendingIntent intent, boolean highPriority)

Since: API Level 11

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.

Parameters
intent The pending intent to launch.
highPriority Passing true will cause this notification to be sent even if other notifications are suppressed.

public Notification.Builder setLargeIcon (Bitmap icon)

Since: API Level 11

Set the large icon that is shown in the ticker and notification.

public Notification.Builder setLights (int argb, int onMs, int offMs)

Since: API Level 11

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

public Notification.Builder setNumber (int number)

Since: API Level 11

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.

public Notification.Builder setOngoing (boolean ongoing)

Since: API Level 11

Set whether this is an ongoing notification.

Ongoing notifications differ from regular notifications in the following ways:

  • Ongoing notifications are sorted above the regular notifications in the notification panel.
  • Ongoing notifications do not have an 'X' close button, and are not affected by the "Clear all" button.

public Notification.Builder setOnlyAlertOnce (boolean onlyAlertOnce)

Since: API Level 11

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

public Notification.Builder setProgress (int max, int progress, boolean indeterminate)

Since: API Level 14

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

public Notification.Builder setSmallIcon (int icon, int level)

Since: API Level 11

A variant of setSmallIcon(int) that takes an additional level parameter for when the icon is a LevelListDrawable.

Parameters
icon A resource ID in the application's package of the drawble to use.
level The level to use for the icon.

public Notification.Builder setSmallIcon (int icon)

Since: API Level 11

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

Parameters
icon A resource ID in the application's package of the drawble to use.

public Notification.Builder setSound (Uri sound)

Since: API Level 11

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

public Notification.Builder setSound (Uri sound, int streamType)

Since: API Level 11

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

public Notification.Builder setTicker (CharSequence tickerText, RemoteViews views)

Since: API Level 11

Set the text that is displayed in the status bar when the notification first arrives, and also a RemoteViews object that may be displayed instead on some devices.

public Notification.Builder setTicker (CharSequence tickerText)

Since: API Level 11

Set the text that is displayed in the status bar when the notification first arrives.

public Notification.Builder setVibrate (long[] pattern)

Since: API Level 11

Set the vibration pattern to use.

public Notification.Builder setWhen (long when)

Since: API Level 11

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