public class Notification extends Object implements Parcelable
NotificationManager
.
The Notification.Builder
has been added to make it
easier to construct Notifications.
For a guide to creating notifications, read the Status Bar Notifications developer guide.
Modifier and Type | Class and Description |
---|---|
static class |
Notification.BigPictureStyle
Helper class for generating large-format notifications that include a large image attachment.
|
static class |
Notification.BigTextStyle
Helper class for generating large-format notifications that include a lot of text.
|
static class |
Notification.Builder
Builder class for
Notification objects. |
static class |
Notification.InboxStyle
Helper class for generating large-format notifications that include a list of (up to 5) strings.
|
static class |
Notification.Style
An object that can apply a rich notification style to a
Notification.Builder
object. |
Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T>
Modifier and Type | Field and Description |
---|---|
int |
audioStreamType
The audio stream type to use when playing the sound.
|
RemoteViews |
bigContentView
A large-format version of
contentView , giving the Notification an
opportunity to show more detail. |
PendingIntent |
contentIntent
The intent to execute when the expanded status entry is clicked.
|
RemoteViews |
contentView
The view that will represent this notification in the expanded status bar.
|
static Parcelable.Creator<Notification> |
CREATOR
Parcelable.Creator that instantiates Notification objects
|
static int |
DEFAULT_ALL
Use all default values (where applicable).
|
static int |
DEFAULT_LIGHTS
Use the default notification lights.
|
static int |
DEFAULT_SOUND
Use the default notification sound.
|
static int |
DEFAULT_VIBRATE
Use the default notification vibrate.
|
int |
defaults
Specifies which values should be taken from the defaults.
|
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.
|
static String |
EXTRA_PEOPLE
Extra key for people values (type TBD).
|
static 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. |
static 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. |
static int |
FLAG_HIGH_PRIORITY
Deprecated.
Use
priority with a positive value. |
static 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. |
static 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. |
static 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. |
static 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. |
static 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 |
flags |
PendingIntent |
fullScreenIntent
An intent to launch instead of posting the notification to the status bar.
|
int |
icon
The resource id of a drawable to use as the icon in the status bar.
|
int |
iconLevel
If the icon in the status bar is to have more than one level, you can set this.
|
String[] |
kind |
static String |
KIND_CALL |
static String |
KIND_EMAIL |
static String |
KIND_EVENT |
static String |
KIND_MESSAGE |
static String |
KIND_PROMO |
Bitmap |
largeIcon
The bitmap that may escape the bounds of the panel and bar.
|
int |
ledARGB
The color of the led.
|
int |
ledOffMS
The number of milliseconds for the LED to be off while it's flashing.
|
int |
ledOnMS
The number of milliseconds for the LED to be on while it's flashing.
|
int |
number
The number of events that this notification represents.
|
int |
priority
Relative priority for this notification.
|
static int |
PRIORITY_DEFAULT
Default notification
priority . |
static int |
PRIORITY_HIGH
Higher
priority , for more important notifications or alerts. |
static int |
PRIORITY_LOW
Lower
priority , for items that are less important. |
static int |
PRIORITY_MAX
Highest
priority , for your application's most important items that require the
user's prompt attention or input. |
static int |
PRIORITY_MIN
Lowest
priority ; these items might not be shown to the user except under special
circumstances, such as detailed notification logs. |
Uri |
sound
The sound to play.
|
static int |
STREAM_DEFAULT
Use this constant as the value for audioStreamType to request that
the default stream type for notifications be used.
|
CharSequence |
tickerText
Text to scroll across the screen when this item is added to
the status bar on large and smaller devices.
|
RemoteViews |
tickerView
The view to show as the ticker in the status bar when the notification
is posted.
|
long[] |
vibrate
The pattern with which to vibrate.
|
long |
when
A timestamp related to this notification, in milliseconds since the epoch.
|
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_WRITE_RETURN_VALUE
Constructor and Description |
---|
Notification()
Constructs a Notification object with default values.
|
Notification(Context context,
int icon,
CharSequence tickerText,
long when,
CharSequence contentTitle,
CharSequence contentText,
Intent contentIntent) |
Notification(int icon,
CharSequence tickerText,
long when)
Deprecated.
Use
Notification.Builder instead. |
Notification(Parcel parcel)
Unflatten the notification from a parcel.
|
Modifier and Type | Method and Description |
---|---|
Notification |
clone()
Creates and returns a copy of this
Object . |
int |
describeContents()
Describe the kinds of special objects contained in this Parcelable's
marshalled representation.
|
void |
setLatestEventInfo(Context context,
CharSequence contentTitle,
CharSequence contentText,
PendingIntent contentIntent)
Deprecated.
Use
Notification.Builder instead. |
void |
setUser(UserHandle user) |
String |
toString()
Returns a string containing a concise, human-readable description of this
object.
|
void |
writeToParcel(Parcel parcel,
int flags)
Flatten this notification from a parcel.
|
public static final int DEFAULT_ALL
public static final int DEFAULT_SOUND
sound
.defaults
,
Constant Field Valuespublic static final int DEFAULT_VIBRATE
vibrate
. Using phone vibration requires the
VIBRATE
permission.defaults
,
Constant Field Valuespublic static final int DEFAULT_LIGHTS
FLAG_SHOW_LIGHTS
bit, and ledARGB
, ledOffMS
, or
ledOnMS
.defaults
,
Constant Field Valuespublic long when
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:
public int icon
public int iconLevel
public int number
Build.VERSION_CODES.HONEYCOMB
, this number was
superimposed over the icon in the status bar. Starting with
Build.VERSION_CODES.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 PendingIntent contentIntent
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
public PendingIntent fullScreenIntent
public CharSequence tickerText
tickerView
public RemoteViews tickerView
public RemoteViews contentView
public RemoteViews bigContentView
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 Bitmap largeIcon
public static final int STREAM_DEFAULT
AudioManager.STREAM_NOTIFICATION
.public int audioStreamType
AudioManager
.public long[] vibrate
To vibrate the default pattern, see defaults
.
Vibrator.vibrate(long[],int)
public int ledARGB
FLAG_SHOW_LIGHTS
,
flags
public int ledOnMS
FLAG_SHOW_LIGHTS
,
flags
public int ledOffMS
FLAG_SHOW_LIGHTS
,
flags
public int defaults
To set, OR the desired from DEFAULT_SOUND
,
DEFAULT_VIBRATE
, DEFAULT_LIGHTS
. For all default
values, use DEFAULT_ALL
.
public static final int FLAG_SHOW_LIGHTS
flags
field that should be
set if you want the LED on for this notification.
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
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
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
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.public static final int FLAG_AUTO_CANCEL
flags
field that should be
set if the notification should be canceled when it is clicked by the
user. On tablets, thepublic static final int FLAG_NO_CLEAR
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
flags
field that should be
set if this notification represents a currently running service. This
will normally be set for you by Service.startForeground(int, android.app.Notification)
.public static final int FLAG_HIGH_PRIORITY
priority
with a positive value.public int flags
public static final int PRIORITY_DEFAULT
priority
. If your application does not prioritize its own
notifications, use this value for all notifications.public static final int PRIORITY_LOW
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.public static final int PRIORITY_MIN
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
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.public static final int PRIORITY_MAX
priority
, for your application's most important items that require the
user's prompt attention or input.public int priority
public static final String KIND_CALL
public static final String KIND_MESSAGE
public static final String KIND_EMAIL
public static final String KIND_EVENT
public static final String KIND_PROMO
public String[] kind
public static final String EXTRA_PEOPLE
public static final Parcelable.Creator<Notification> CREATOR
public Notification()
Notification.Builder
instead.public Notification(Context context, int icon, CharSequence tickerText, long when, CharSequence contentTitle, CharSequence contentText, Intent contentIntent)
@Deprecated public Notification(int icon, CharSequence tickerText, long when)
Notification.Builder
instead.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 Notification(Parcel parcel)
public Notification clone()
Object
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.public int describeContents()
Parcelable
describeContents
in interface Parcelable
public void writeToParcel(Parcel parcel, int flags)
writeToParcel
in interface Parcelable
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.PARCELABLE_WRITE_RETURN_VALUE
.@Deprecated public void setLatestEventInfo(Context context, CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent)
Notification.Builder
instead.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.
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
Intent.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()
Object
getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toString
method
if you intend implementing your own toString
method.
public void setUser(UserHandle user)