FileDocCategorySizeDatePackage
Notification.javaAPI DocAndroid 5.1 API195253Thu Mar 12 22:22:10 GMT 2015android.app

Notification

public class Notification extends Object implements android.os.Parcelable
A class that represents how a persistent notification is to be presented to the user using the {@link android.app.NotificationManager}.

The {@link Notification.Builder Notification.Builder} has been added to make it easier to construct Notifications.

Developer Guides

For a guide to creating notifications, read the Status Bar Notifications developer guide.

Fields Summary
private static final String
TAG
public static final String
INTENT_CATEGORY_NOTIFICATION_PREFERENCES
An activity that provides a user interface for adjusting notification preferences for its containing application. Optional but recommended for apps that post {@link android.app.Notification Notifications}.
public static final int
DEFAULT_ALL
Use all default values (where applicable).
public static final int
DEFAULT_SOUND
Use the default notification sound. This will ignore any given {@link #sound}.

A notification that is noisy is more likely to be presented as a heads-up notification.

public static final int
DEFAULT_VIBRATE
Use the default notification vibrate. This will ignore any given {@link #vibrate}. Using phone vibration requires the {@link android.Manifest.permission#VIBRATE VIBRATE} permission.

A notification that vibrates is more likely to be presented as a heads-up notification.

public static final int
DEFAULT_LIGHTS
Use the default notification lights. This will ignore the {@link #FLAG_SHOW_LIGHTS} bit, and {@link #ledARGB}, {@link #ledOffMS}, or {@link #ledOnMS}.
private static final int
MAX_CHARSEQUENCE_LENGTH
Maximum length of CharSequences accepted by Builder and friends.

Avoids spamming the system with overly large strings such as full e-mails.

public long
when
A timestamp related to this notification, in milliseconds since the epoch. Default value: {@link System#currentTimeMillis() Now}. Choose a timestamp that will be most relevant to the user. For most finite events, this corresponds to the time the event happened (or will happen, in the case of events that have yet to occur but about which the user is being informed). Indefinite events should be timestamped according to when the activity began. Some examples:
  • Notification of a new chat message should be stamped when the message was received.
  • Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.
  • Notification of a completed file download should be stamped when the download finished.
  • Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).
  • Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time.
  • Notification of an ongoing countdown timer should be stamped with the timer's end time.
public int
icon
The resource id of a drawable to use as the icon in the status bar. This is required; notifications with an invalid icon resource will not be shown.
public int
iconLevel
If the icon in the status bar is to have more than one level, you can set this. Otherwise, leave it at its default value of 0.
public int
number
The number of events that this notification represents. For example, in a new mail notification, this could be the number of unread messages. The system may or may not use this field to modify the appearance of the notification. For example, before {@link android.os.Build.VERSION_CODES#HONEYCOMB}, this number was superimposed over the icon in the status bar. Starting with {@link android.os.Build.VERSION_CODES#HONEYCOMB}, the template used by {@link Notification.Builder} has displayed the number in the expanded notification view. If the number is 0 or negative, it is never shown.
public PendingIntent
contentIntent
The intent to execute when the expanded status entry is clicked. If this is an activity, it must include the {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires that you take care of task management as described in the Tasks and Back Stack document. In particular, make sure to read the notification section Handling Notifications for the correct ways to launch an application from a notification.
public PendingIntent
deleteIntent
The intent to execute when the notification is explicitly dismissed by the user, either with the "Clear All" button or by swiping it away individually. This probably shouldn't be launching an activity since several of those will be sent at the same time.
public PendingIntent
fullScreenIntent
An intent to launch instead of posting the notification to the status bar.

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

public CharSequence
tickerText
Text that summarizes this notification for accessibility services. As of the L release, this text is no longer shown on screen, but it is still useful to accessibility services (where it serves as an audible announcement of the notification's appearance).
public android.widget.RemoteViews
tickerView
Formerly, a view showing the {@link #tickerText}. No longer displayed in the status bar as of API 21.
public android.widget.RemoteViews
contentView
The view that will represent this notification in the expanded status bar.
public android.widget.RemoteViews
bigContentView
A large-format version of {@link #contentView}, giving the Notification an opportunity to show more detail. The system UI may choose to show this instead of the normal content view at its discretion.
public android.widget.RemoteViews
headsUpContentView
A medium-format version of {@link #contentView}, providing the Notification an opportunity to add action buttons to contentView. At its discretion, the system UI may choose to show this as a heads-up notification, which will pop up so the user can see it without leaving their current activity.
public android.graphics.Bitmap
largeIcon
The bitmap that may escape the bounds of the panel and bar.
public android.net.Uri
sound
The sound to play.

A notification that is noisy is more likely to be presented as a heads-up notification.

To play the default notification sound, see {@link #defaults}.

public static final int
STREAM_DEFAULT
Use this constant as the value for audioStreamType to request that the default stream type for notifications be used. Currently the default stream type is {@link AudioManager#STREAM_NOTIFICATION}.
public int
audioStreamType
The audio stream type to use when playing the sound. Should be one of the STREAM_ constants from {@link android.media.AudioManager}.
public static final android.media.AudioAttributes
AUDIO_ATTRIBUTES_DEFAULT
The default value of {@link #audioAttributes}.
public android.media.AudioAttributes
audioAttributes
The {@link AudioAttributes audio attributes} to use when playing the sound.
public long[]
vibrate
The pattern with which to vibrate.

To vibrate the default pattern, see {@link #defaults}.

A notification that vibrates is more likely to be presented as a heads-up notification.

public int
ledARGB
The color of the led. The hardware will do its best approximation.
public int
ledOnMS
The number of milliseconds for the LED to be on while it's flashing. The hardware will do its best approximation.
public int
ledOffMS
The number of milliseconds for the LED to be off while it's flashing. The hardware will do its best approximation.
public int
defaults
Specifies which values should be taken from the defaults.

To set, OR the desired from {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. For all default values, use {@link #DEFAULT_ALL}.

public static final int
FLAG_SHOW_LIGHTS
Bit to be bitwise-ored into the {@link #flags} field that should be set if you want the LED on for this notification.
  • To turn the LED off, pass 0 in the alpha channel for colorARGB or 0 for both ledOnMS and ledOffMS.
  • To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.
  • To flash the LED, pass the number of milliseconds that it should be on and off to ledOnMS and ledOffMS.

Since hardware varies, you are not guaranteed that any of the values you pass are honored exactly. Use the system defaults (TODO) if possible because they will be set to values that work on any given hardware.

The alpha channel must be set for forward compatibility.

public static final int
FLAG_ONGOING_EVENT
Bit to be bitwise-ored into the {@link #flags} field that should be set if this notification is in reference to something that is ongoing, like a phone call. It should not be set if this notification is in reference to something that happened at a particular point in time, like a missed phone call.
public static final int
FLAG_INSISTENT
Bit to be bitwise-ored into the {@link #flags} field that if set, the audio will be repeated until the notification is cancelled or the notification window is opened.
public static final int
FLAG_ONLY_ALERT_ONCE
Bit to be bitwise-ored into the {@link #flags} field that should be set if you would only like the sound, vibrate and ticker to be played if the notification was not already showing.
public static final int
FLAG_AUTO_CANCEL
Bit to be bitwise-ored into the {@link #flags} field that should be set if the notification should be canceled when it is clicked by the user.
public static final int
FLAG_NO_CLEAR
Bit to be bitwise-ored into the {@link #flags} field that should be set if the notification should not be canceled when the user clicks the Clear all button.
public static final int
FLAG_FOREGROUND_SERVICE
Bit to be bitwise-ored into the {@link #flags} field that should be set if this notification represents a currently running service. This will normally be set for you by {@link Service#startForeground}.
public static final int
FLAG_HIGH_PRIORITY
Obsolete flag indicating high-priority notifications; use the priority field instead.
public static final int
FLAG_LOCAL_ONLY
Bit to be bitswise-ored into the {@link #flags} field that should be set if this notification is relevant to the current device only and it is not recommended that it bridge to other devices.
public static final int
FLAG_GROUP_SUMMARY
Bit to be bitswise-ored into the {@link #flags} field that should be set if this notification is 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 {@link Builder#setGroup}.
public int
flags
public static final int
PRIORITY_DEFAULT
Default notification {@link #priority}. If your application does not prioritize its own notifications, use this value for all notifications.
public static final int
PRIORITY_LOW
Lower {@link #priority}, for items that are less important. The UI may choose to show these items smaller, or at a different position in the list, compared with your app's {@link #PRIORITY_DEFAULT} items.
public static final int
PRIORITY_MIN
Lowest {@link #priority}; these items might not be shown to the user except under special circumstances, such as detailed notification logs.
public static final int
PRIORITY_HIGH
Higher {@link #priority}, for more important notifications or alerts. The UI may choose to show these items larger, or at a different position in notification lists, compared with your app's {@link #PRIORITY_DEFAULT} items.
public static final int
PRIORITY_MAX
Highest {@link #priority}, for your application's most important items that require the user's prompt attention or input.
public int
priority
Relative priority for this notification. Priority is an indication of how much of the user's valuable attention should be consumed by this notification. Low-priority notifications may be hidden from the user in certain situations, while the user might be interrupted for a higher-priority notification. The system will make a determination about how to interpret this priority when presenting the notification.

A notification that is at least {@link #PRIORITY_HIGH} is more likely to be presented as a heads-up notification.

public int
color
Accent color (an ARGB integer like the constants in {@link android.graphics.Color}) to be applied by the standard Style templates when presenting this notification. The current template design constructs a colorful header image by overlaying the {@link #icon} image (stenciled in white) atop a field of this color. Alpha components are ignored.
public static final int
COLOR_DEFAULT
Special value of {@link #color} telling the system not to decorate this notification with any special color but instead use default colors when presenting this notification.
public int
visibility
Sphere of visibility of this notification, which affects how and when the SystemUI reveals the notification's presence and contents in untrusted situations (namely, on the secure lockscreen). The default level, {@link #VISIBILITY_PRIVATE}, behaves exactly as notifications have always done on Android: The notification's {@link #icon} and {@link #tickerText} (if available) are shown in all situations, but the contents are only available if the device is unlocked for the appropriate user. A more permissive policy can be expressed by {@link #VISIBILITY_PUBLIC}; such a notification can be read even in an "insecure" context (that is, above a secure lockscreen). To modify the public version of this notificationâ