Notification
implements Parcelable
Notification
extends Objectimplements Parcelable
java.lang.Object | |
↳ | android.app.Notification |
Class Overview
A class that represents how a persistent notification is to be presented to
the user using the
The NotificationManager
.
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.Summary
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Notification.BigPictureStyle | Helper class for generating large-format notifications that include a large image attachment. | ||||||||||
Notification.BigTextStyle | Helper class for generating large-format notifications that include a lot of text. | ||||||||||
Notification.Builder | Builder class for Notification objects. |
||||||||||
Notification.InboxStyle | Helper class for generating large-format notifications that include a list of (up to 5) strings. | ||||||||||
Notification.Style | An object that can apply a rich notification style to a Notification.Builder
object. |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | DEFAULT_ALL | Use all default values (where applicable). | |||||||||
int | DEFAULT_LIGHTS | Use the default notification lights. | |||||||||
int | DEFAULT_SOUND | Use the default notification sound. | |||||||||
int | DEFAULT_VIBRATE | Use the default notification vibrate. | |||||||||
int | FLAG_AUTO_CANCEL | Bit to be bitwise-ored into the flags field that should be
set if the notification should be canceled when it is clicked by the
user. |
|||||||||
int | FLAG_FOREGROUND_SERVICE | Bit to be bitwise-ored into the flags field that should be
set if this notification represents a currently running service. |
|||||||||
int | FLAG_HIGH_PRIORITY |
This constant was deprecated
in API level 16.
Use priority with a positive value.
|
|||||||||
int | FLAG_INSISTENT | Bit to be bitwise-ored into the flags field that if set,
the audio will be repeated until the notification is
cancelled or the notification window is opened. |
|||||||||
int | FLAG_NO_CLEAR | Bit to be bitwise-ored into the flags field that should be
set if the notification should not be canceled when the user clicks
the Clear all button. |
|||||||||
int | FLAG_ONGOING_EVENT | Bit to be bitwise-ored into the flags field that should be
set if this notification is in reference to something that is ongoing,
like a phone call. |
|||||||||
int | FLAG_ONLY_ALERT_ONCE | Bit to be bitwise-ored into the flags field that should be
set if you want the sound and/or vibration play each time the
notification is sent, even if it has not been canceled before that. |
|||||||||
int | FLAG_SHOW_LIGHTS | Bit to be bitwise-ored into the flags field that should be
set if you want the LED on for this notification. |
|||||||||
int | PRIORITY_DEFAULT | Default notification priority . |
|||||||||
int | PRIORITY_HIGH | Higher priority , for more important notifications or alerts. |
|||||||||
int | PRIORITY_LOW | Lower priority , for items that are less important. |
|||||||||
int | PRIORITY_MAX | Highest priority , for your application's most important items that require the
user's prompt attention or input. |
|||||||||
int | PRIORITY_MIN | Lowest priority ; these items might not be shown to the user except under special
circumstances, such as detailed notification logs. |
|||||||||
int | STREAM_DEFAULT | Use this constant as the value for audioStreamType to request that the default stream type for notifications be used. |
[Expand]
Inherited Constants
| |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface
android.os.Parcelable
|
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
CREATOR | Parcelable.Creator that instantiates Notification objects | ||||||||||
audioStreamType | The audio stream type to use when playing the sound. | ||||||||||
bigContentView | A large-format version of contentView , giving the Notification an
opportunity to show more detail. |
||||||||||
contentIntent | The intent to execute when the expanded status entry is clicked. | ||||||||||
contentView | The view that will represent this notification in the expanded status bar. | ||||||||||
defaults | Specifies which values should be taken from the defaults. | ||||||||||
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. | ||||||||||
flags | |||||||||||
fullScreenIntent | An intent to launch instead of posting the notification to the status bar. | ||||||||||
icon | The resource id of a drawable to use as the icon in the status bar. | ||||||||||
iconLevel | If the icon in the status bar is to have more than one level, you can set this. | ||||||||||
largeIcon | The bitmap that may escape the bounds of the panel and bar. | ||||||||||
ledARGB | The color of the led. | ||||||||||
ledOffMS | The number of milliseconds for the LED to be off while it's flashing. | ||||||||||
ledOnMS | The number of milliseconds for the LED to be on while it's flashing. | ||||||||||
number | The number of events that this notification represents. | ||||||||||
priority | Relative priority for this notification. | ||||||||||
sound | The sound to play. | ||||||||||
tickerText | Text to scroll across the screen when this item is added to the status bar on large and smaller devices. | ||||||||||
tickerView | The view to show as the ticker in the status bar when the notification is posted. | ||||||||||
vibrate | The pattern with which to vibrate. | ||||||||||
when | A timestamp related to this notification, in milliseconds since the epoch. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a Notification object with default values.
| |||||||||||
This constructor was deprecated
in API level 11.
Use
Notification.Builder instead.
| |||||||||||
Unflatten the notification from a parcel.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates and returns a copy of this
Object . | |||||||||||
Describe the kinds of special objects contained in this Parcelable's
marshalled representation.
| |||||||||||
This method was deprecated
in API level 11.
Use
Notification.Builder instead.
| |||||||||||
Returns a string containing a concise, human-readable description of this
object.
| |||||||||||
Flatten this notification from a parcel.
|
[Expand]
Inherited Methods
| |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
android.os.Parcelable
|
Constants
public static final int DEFAULT_ALL
Added in API level 1
Use all default values (where applicable).
Constant Value:
-1
(0xffffffff)
public static final int DEFAULT_LIGHTS
Added in API level 1
Use the default notification lights. This will ignore the
FLAG_SHOW_LIGHTS
bit, and ledARGB
, ledOffMS
, or
ledOnMS
.See Also
Constant Value:
4
(0x00000004)
public static final int DEFAULT_SOUND
Added in API level 1
public static final int DEFAULT_VIBRATE
Added in API level 1
public static final int FLAG_AUTO_CANCEL
Added in API level 1
Bit to be bitwise-ored into the
flags
field that should be
set if the notification should be canceled when it is clicked by the
user.
Constant Value:
16
(0x00000010)
public static final int FLAG_FOREGROUND_SERVICE
Added in API level 5
Bit to be bitwise-ored into the
flags
field that should be
set if this notification represents a currently running service. This
will normally be set for you by startForeground(int, Notification)
.
Constant Value:
64
(0x00000040)
public static final int FLAG_HIGH_PRIORITY
Added in API level 11
This constant was deprecated
in API level 16.
Use
Use
priority
with a positive value.
Obsolete flag indicating high-priority notifications; use the priority field instead.
Constant Value:
128
(0x00000080)
public static final int FLAG_INSISTENT
Added in API level 1
Bit to be bitwise-ored into the
flags
field that if set,
the audio will be repeated until the notification is
cancelled or the notification window is opened.
Constant Value:
4
(0x00000004)
public static final int FLAG_NO_CLEAR
Added in API level 1
Bit to be bitwise-ored into the
flags
field that should be
set if the notification should not be canceled when the user clicks
the Clear all button.
Constant Value:
32
(0x00000020)
public static final int FLAG_ONGOING_EVENT
Added in API level 1
Bit to be bitwise-ored into the
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.
Constant Value:
2
(0x00000002)
public static final int FLAG_ONLY_ALERT_ONCE
Added in API level 1
Bit to be bitwise-ored into the
flags
field that should be
set if you want the sound and/or vibration play each time the
notification is sent, even if it has not been canceled before that.
Constant Value:
8
(0x00000008)
public static final int FLAG_SHOW_LIGHTS
Added in API level 1
Bit to be bitwise-ored into the
The alpha channel must be set for forward compatibility.
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.
The alpha channel must be set for forward compatibility.
Constant Value:
1
(0x00000001)
public static final int PRIORITY_DEFAULT
Added in API level 16
Default notification
priority
. If your application does not prioritize its own
notifications, use this value for all notifications.
Constant Value:
0
(0x00000000)
public static final int PRIORITY_HIGH
Added in API level 16
Higher
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 PRIORITY_DEFAULT
items.
Constant Value:
1
(0x00000001)
public static final int PRIORITY_LOW
Added in API level 16
Lower
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
PRIORITY_DEFAULT
items.
Constant Value:
-1
(0xffffffff)
public static final int PRIORITY_MAX
Added in API level 16
Highest
priority
, for your application's most important items that require the
user's prompt attention or input.
Constant Value:
2
(0x00000002)
public static final int PRIORITY_MIN
Added in API level 16
Lowest
priority
; these items might not be shown to the user except under special
circumstances, such as detailed notification logs.
Constant Value:
-2
(0xfffffffe)
public static final int STREAM_DEFAULT
Added in API level 1
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
STREAM_NOTIFICATION
.
Constant Value:
-1
(0xffffffff)
Fields
public static final Creator<Notification> CREATOR
Added in API level 1
Parcelable.Creator that instantiates Notification objects
public int audioStreamType
Added in API level 1
The audio stream type to use when playing the sound.
Should be one of the STREAM_ constants from
AudioManager
.
public RemoteViews bigContentView
Added in API level 16
A large-format version of
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 PendingIntent contentIntent
Added in API level 1
The intent to execute when the expanded status entry is clicked. If
this is an activity, it must include the
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 RemoteViews contentView
Added in API level 1
The view that will represent this notification in the expanded status bar.
public int defaults
Added in API level 1
Specifies which values should be taken from the defaults.
To set, OR the desired from
To set, OR the desired from
DEFAULT_SOUND
,
DEFAULT_VIBRATE
, DEFAULT_LIGHTS
. For all default
values, use DEFAULT_ALL
.
public PendingIntent deleteIntent
Added in API level 1
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
Added in API level 9
An intent to launch instead of posting the notification to the status bar.
public int icon
Added in API level 1
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
Added in API level 1
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 Bitmap largeIcon
Added in API level 11
The bitmap that may escape the bounds of the panel and bar.
public int ledARGB
Added in API level 1
The color of the led. The hardware will do its best approximation.
See Also
public int ledOffMS
Added in API level 1
The number of milliseconds for the LED to be off while it's flashing.
The hardware will do its best approximation.
See Also
public int ledOnMS
Added in API level 1
The number of milliseconds for the LED to be on while it's flashing.
The hardware will do its best approximation.
See Also
public int number
Added in API level 1
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
HONEYCOMB
, this number was
superimposed over the icon in the status bar. Starting with
HONEYCOMB
, the template used by
Notification.Builder
has displayed the number in the expanded notification view.
If the number is 0 or negative, it is never shown.
public int priority
Added in API level 16
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.
public CharSequence tickerText
Added in API level 1
Text to scroll across the screen when this item is added to
the status bar on large and smaller devices.
See Also
public RemoteViews tickerView
Added in API level 11
The view to show as the ticker in the status bar when the notification
is posted.
public long[] vibrate
Added in API level 1
The pattern with which to vibrate.
To vibrate the default pattern, see
To vibrate the default pattern, see
defaults
.
See Also
public long when
Added in API level 1
A timestamp related to this notification, in milliseconds since the epoch.
Default value:
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 Constructors
public Notification ()
Added in API level 1
Constructs a Notification object with default values.
You might want to consider using
Notification.Builder
instead.
public Notification (int icon, CharSequence tickerText, long when)
Added in API level 1
This constructor was deprecated
in API level 11.
Use
Use
Notification.Builder
instead.
Constructs a Notification object with the information needed to
have a status bar icon without the standard expanded view.
Parameters
icon | The resource id of the icon to put in the status bar. |
---|---|
tickerText | The text that flows by in the status bar when the notification first activates. |
when | The time to show in the time field. In the System.currentTimeMillis timebase. |
Public Methods
public Notification clone ()
Added in API level 1
Creates and returns a copy of this
Object
. The default
implementation returns a so-called "shallow" copy: It creates a new
instance of the same class and then copies the field values (including
object references) from this instance to the new instance. A "deep" copy,
in contrast, would also recursively clone nested objects. A subclass that
needs to implement this kind of cloning should call super.clone()
to create the new instance and then create deep copies of the nested,
mutable objects.Returns
- a copy of this object.
public int describeContents ()
Added in API level 1
Describe the kinds of special objects contained in this Parcelable's
marshalled representation.
Returns
- a bitmask indicating the set of special object types marshalled by the Parcelable.
public void setLatestEventInfo (Context context, CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent)
Added in API level 1
This method was deprecated
in API level 11.
Use
Use
Notification.Builder
instead.
Sets the
Uses the
contentView
field to be a view with the standard "Latest Event"
layout.
Uses the
icon
and when
fields to set the icon and time fields
in the view.Parameters
context | The context for your application / activity. |
---|---|
contentTitle | The title that goes in the expanded entry. |
contentText | The text that goes in the expanded entry. |
contentIntent | The intent to launch when the user clicks the expanded notification.
If this is an activity, it must include the
FLAG_ACTIVITY_NEW_TASK flag, which requires
that you take care of task management as described in the
Tasks and Back
Stack document. |
public String toString ()
Added in API level 1
Returns a string containing a concise, human-readable description of this
object. Subclasses are encouraged to override this method and provide an
implementation that takes into account the object's type and data. The
default implementation is equivalent to the following expression:
getClass().getName() + '@' + Integer.toHexString(hashCode())See Writing a useful
toString
method
if you intend implementing your own toString
method.Returns
- a printable representation of this object.
public void writeToParcel (Parcel parcel, int flags)
Added in API level 1
Flatten this notification from a parcel.
Parameters
parcel | The Parcel in which the object should be written. |
---|---|
flags | Additional flags about how the object should be written.
May be 0 or PARCELABLE_WRITE_RETURN_VALUE .
|