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‚¨for example, to redact some portions‚¨see {@link Builder#setPublicVersion(Notification)}. Finally, a notification can be made {@link #VISIBILITY_SECRET}, which will suppress its icon and ticker until the user has bypassed the lockscreen.
public static final int
VISIBILITY_PUBLIC
Notification visibility: Show this notification in its entirety on all lockscreens. {@see #visibility}
public static final int
VISIBILITY_PRIVATE
Notification visibility: Show this notification on all lockscreens, but conceal sensitive or private information on secure lockscreens. {@see #visibility}
public static final int
VISIBILITY_SECRET
Notification visibility: Do not reveal any part of this notification on a secure lockscreen. {@see #visibility}
public static final String
CATEGORY_CALL
Notification category: incoming call (voice or video) or similar synchronous communication request.
public static final String
CATEGORY_MESSAGE
Notification category: incoming direct message (SMS, instant message, etc.).
public static final String
CATEGORY_EMAIL
Notification category: asynchronous bulk message (email).
public static final String
CATEGORY_EVENT
Notification category: calendar event.
public static final String
CATEGORY_PROMO
Notification category: promotion or advertisement.
public static final String
CATEGORY_ALARM
Notification category: alarm or timer.
public static final String
CATEGORY_PROGRESS
Notification category: progress of a long-running background operation.
public static final String
CATEGORY_SOCIAL
Notification category: social network or sharing update.
public static final String
CATEGORY_ERROR
Notification category: error in background operation or authentication status.
public static final String
CATEGORY_TRANSPORT
Notification category: media transport control for playback.
public static final String
CATEGORY_SYSTEM
Notification category: system or device status update. Reserved for system use.
public static final String
CATEGORY_SERVICE
Notification category: indication of running background service.
public static final String
CATEGORY_RECOMMENDATION
Notification category: a specific, timely recommendation for a single thing. For example, a news app might want to recommend a news story it believes the user will want to read next.
public static final String
CATEGORY_STATUS
Notification category: ongoing information about device or contextual status.
public String
category
One of the predefined notification categories (see the CATEGORY_* constants) that best describes this Notification. May be used by the system for ranking and filtering.
private String
mGroupKey
private String
mSortKey
public android.os.Bundle
extras
Additional semantic data to be carried around with this Notification.

The extras keys defined here are intended to capture the original inputs to {@link Builder} APIs, and are intended to be used by {@link android.service.notification.NotificationListenerService} implementations to extract detailed information from notification objects.

public static final String
EXTRA_TITLE
{@link #extras} key: this is the title of the notification, as supplied to {@link Builder#setContentTitle(CharSequence)}.
public static final String
EXTRA_TITLE_BIG
{@link #extras} key: this is the title of the notification when shown in expanded form, e.g. as supplied to {@link BigTextStyle#setBigContentTitle(CharSequence)}.
public static final String
EXTRA_TEXT
{@link #extras} key: this is the main text payload, as supplied to {@link Builder#setContentText(CharSequence)}.
public static final String
EXTRA_SUB_TEXT
{@link #extras} key: this is a third line of text, as supplied to {@link Builder#setSubText(CharSequence)}.
public static final String
EXTRA_INFO_TEXT
{@link #extras} key: this is a small piece of additional text as supplied to {@link Builder#setContentInfo(CharSequence)}.
public static final String
EXTRA_SUMMARY_TEXT
{@link #extras} key: this is a line of summary information intended to be shown alongside expanded notifications, as supplied to (e.g.) {@link BigTextStyle#setSummaryText(CharSequence)}.
public static final String
EXTRA_BIG_TEXT
{@link #extras} key: this is the longer text shown in the big form of a {@link BigTextStyle} notification, as supplied to {@link BigTextStyle#bigText(CharSequence)}.
public static final String
EXTRA_SMALL_ICON
{@link #extras} key: this is the resource ID of the notification's main small icon, as supplied to {@link Builder#setSmallIcon(int)}.
public static final String
EXTRA_LARGE_ICON
{@link #extras} key: this is a bitmap to be used instead of the small icon when showing the notification payload, as supplied to {@link Builder#setLargeIcon(android.graphics.Bitmap)}.
public static final String
EXTRA_LARGE_ICON_BIG
{@link #extras} key: this is a bitmap to be used instead of the one from {@link Builder#setLargeIcon(android.graphics.Bitmap)} when the notification is shown in its expanded form, as supplied to {@link BigPictureStyle#bigLargeIcon(android.graphics.Bitmap)}.
public static final String
EXTRA_PROGRESS
{@link #extras} key: this is the progress value supplied to {@link Builder#setProgress(int, int, boolean)}.
public static final String
EXTRA_PROGRESS_MAX
{@link #extras} key: this is the maximum value supplied to {@link Builder#setProgress(int, int, boolean)}.
public static final String
EXTRA_PROGRESS_INDETERMINATE
{@link #extras} key: whether the progress bar is indeterminate, supplied to {@link Builder#setProgress(int, int, boolean)}.
public static final String
EXTRA_SHOW_CHRONOMETER
{@link #extras} key: whether {@link #when} should be shown as a count-up timer (specifically a {@link android.widget.Chronometer}) instead of a timestamp, as supplied to {@link Builder#setUsesChronometer(boolean)}.
public static final String
EXTRA_SHOW_WHEN
{@link #extras} key: whether {@link #when} should be shown, as supplied to {@link Builder#setShowWhen(boolean)}.
public static final String
EXTRA_PICTURE
{@link #extras} key: this is a bitmap to be shown in {@link BigPictureStyle} expanded notifications, supplied to {@link BigPictureStyle#bigPicture(android.graphics.Bitmap)}.
public static final String
EXTRA_TEXT_LINES
{@link #extras} key: An array of CharSequences to show in {@link InboxStyle} expanded notifications, each of which was supplied to {@link InboxStyle#addLine(CharSequence)}.
public static final String
EXTRA_TEMPLATE
{@link #extras} key: A string representing the name of the specific {@link android.app.Notification.Style} used to create this notification.
public static final String
EXTRA_PEOPLE
{@link #extras} key: A String array containing the people that this notification relates to, each of which was supplied to {@link Builder#addPerson(String)}.
public static final String
EXTRA_AS_HEADS_UP
{@link #extras} key: used to provide hints about the appropriateness of displaying this notification as a heads-up notification.
public static final String
EXTRA_ALLOW_DURING_SETUP
Allow certain system-generated notifications to appear before the device is provisioned. Only available to notifications coming from the android package.
public static final String
EXTRA_BACKGROUND_IMAGE_URI
{@link #extras} key: A {@link android.content.ContentUris content URI} pointing to an image that can be displayed in the background when the notification is selected. The URI must point to an image stream suitable for passing into {@link android.graphics.BitmapFactory#decodeStream(java.io.InputStream) BitmapFactory.decodeStream}; all other content types will be ignored. The content provider URI used for this purpose must require no permissions to read the image data.
public static final String
EXTRA_MEDIA_SESSION
{@link #extras} key: A {@link android.media.session.MediaSession.Token} associated with a {@link android.app.Notification.MediaStyle} notification.
public static final String
EXTRA_COMPACT_ACTIONS
{@link #extras} key: the indices of actions to be shown in the compact view, as supplied to (e.g.) {@link MediaStyle#setShowActionsInCompactView(int...)}.
public static final String
EXTRA_ORIGINATING_USERID
{@link #extras} key: the user that built the notification.
public static final int
HEADS_UP_NEVER
Value for {@link #EXTRA_AS_HEADS_UP} that indicates this notification should not be displayed in the heads up space.

If this notification has a {@link #fullScreenIntent}, then it will always launch the full-screen intent when posted.

public static final int
HEADS_UP_ALLOWED
Default value for {@link #EXTRA_AS_HEADS_UP} that indicates this notification may be displayed as a heads up.
public static final int
HEADS_UP_REQUESTED
Value for {@link #EXTRA_AS_HEADS_UP} that indicates this notification is a good candidate for display as a heads up.
public Action[]
actions
Array of all {@link Action} structures attached to this notification by {@link Builder#addAction(int, CharSequence, PendingIntent)}. Mostly useful for instances of {@link android.service.notification.NotificationListenerService} that provide an alternative interface for invoking actions.
public Notification
publicVersion
Replacement version of this notification whose content will be shown in an insecure context such as atop a secure keyguard. See {@link #visibility} and {@link #VISIBILITY_PUBLIC}.
public static final Parcelable.Creator
CREATOR
Parcelable.Creator that instantiates Notification objects
Constructors Summary
public Notification()
Constructs a Notification object with default values. You might want to consider using {@link Builder} instead.

        this.when = System.currentTimeMillis();
        this.priority = PRIORITY_DEFAULT;
    
public Notification(android.content.Context context, int icon, CharSequence tickerText, long when, CharSequence contentTitle, CharSequence contentText, android.content.Intent contentIntent)

hide

        this.when = when;
        this.icon = icon;
        this.tickerText = tickerText;
        setLatestEventInfo(context, contentTitle, contentText,
                PendingIntent.getActivity(context, 0, contentIntent, 0));
    
public Notification(int icon, CharSequence tickerText, long when)
Constructs a Notification object with the information needed to have a status bar icon without the standard expanded view.

param
icon The resource id of the icon to put in the status bar.
param
tickerText The text that flows by in the status bar when the notification first activates.
param
when The time to show in the time field. In the System.currentTimeMillis timebase.
deprecated
Use {@link Builder} instead.

        this.icon = icon;
        this.tickerText = tickerText;
        this.when = when;
    
public Notification(android.os.Parcel parcel)
Unflatten the notification from a parcel.

        int version = parcel.readInt();

        when = parcel.readLong();
        icon = parcel.readInt();
        number = parcel.readInt();
        if (parcel.readInt() != 0) {
            contentIntent = PendingIntent.CREATOR.createFromParcel(parcel);
        }
        if (parcel.readInt() != 0) {
            deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel);
        }
        if (parcel.readInt() != 0) {
            tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
        }
        if (parcel.readInt() != 0) {
            tickerView = RemoteViews.CREATOR.createFromParcel(parcel);
        }
        if (parcel.readInt() != 0) {
            contentView = RemoteViews.CREATOR.createFromParcel(parcel);
        }
        if (parcel.readInt() != 0) {
            largeIcon = Bitmap.CREATOR.createFromParcel(parcel);
        }
        defaults = parcel.readInt();
        flags = parcel.readInt();
        if (parcel.readInt() != 0) {
            sound = Uri.CREATOR.createFromParcel(parcel);
        }

        audioStreamType = parcel.readInt();
        if (parcel.readInt() != 0) {
            audioAttributes = AudioAttributes.CREATOR.createFromParcel(parcel);
        }
        vibrate = parcel.createLongArray();
        ledARGB = parcel.readInt();
        ledOnMS = parcel.readInt();
        ledOffMS = parcel.readInt();
        iconLevel = parcel.readInt();

        if (parcel.readInt() != 0) {
            fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel);
        }

        priority = parcel.readInt();

        category = parcel.readString();

        mGroupKey = parcel.readString();

        mSortKey = parcel.readString();

        extras = parcel.readBundle(); // may be null

        actions = parcel.createTypedArray(Action.CREATOR); // may be null

        if (parcel.readInt() != 0) {
            bigContentView = RemoteViews.CREATOR.createFromParcel(parcel);
        }

        if (parcel.readInt() != 0) {
            headsUpContentView = RemoteViews.CREATOR.createFromParcel(parcel);
        }

        visibility = parcel.readInt();

        if (parcel.readInt() != 0) {
            publicVersion = Notification.CREATOR.createFromParcel(parcel);
        }

        color = parcel.readInt();
    
Methods Summary
public android.app.Notificationclone()

        Notification that = new Notification();
        cloneInto(that, true);
        return that;
    
public voidcloneInto(android.app.Notification that, boolean heavy)
Copy all (or if heavy is false, all except Bitmaps and RemoteViews) members of this into that.

hide

        that.when = this.when;
        that.icon = this.icon;
        that.number = this.number;

        // PendingIntents are global, so there's no reason (or way) to clone them.
        that.contentIntent = this.contentIntent;
        that.deleteIntent = this.deleteIntent;
        that.fullScreenIntent = this.fullScreenIntent;

        if (this.tickerText != null) {
            that.tickerText = this.tickerText.toString();
        }
        if (heavy && this.tickerView != null) {
            that.tickerView = this.tickerView.clone();
        }
        if (heavy && this.contentView != null) {
            that.contentView = this.contentView.clone();
        }
        if (heavy && this.largeIcon != null) {
            that.largeIcon = Bitmap.createBitmap(this.largeIcon);
        }
        that.iconLevel = this.iconLevel;
        that.sound = this.sound; // android.net.Uri is immutable
        that.audioStreamType = this.audioStreamType;
        if (this.audioAttributes != null) {
            that.audioAttributes = new AudioAttributes.Builder(this.audioAttributes).build();
        }

        final long[] vibrate = this.vibrate;
        if (vibrate != null) {
            final int N = vibrate.length;
            final long[] vib = that.vibrate = new long[N];
            System.arraycopy(vibrate, 0, vib, 0, N);
        }

        that.ledARGB = this.ledARGB;
        that.ledOnMS = this.ledOnMS;
        that.ledOffMS = this.ledOffMS;
        that.defaults = this.defaults;

        that.flags = this.flags;

        that.priority = this.priority;

        that.category = this.category;

        that.mGroupKey = this.mGroupKey;

        that.mSortKey = this.mSortKey;

        if (this.extras != null) {
            try {
                that.extras = new Bundle(this.extras);
                // will unparcel
                that.extras.size();
            } catch (BadParcelableException e) {
                Log.e(TAG, "could not unparcel extras from notification: " + this, e);
                that.extras = null;
            }
        }

        if (this.actions != null) {
            that.actions = new Action[this.actions.length];
            for(int i=0; i<this.actions.length; i++) {
                that.actions[i] = this.actions[i].clone();
            }
        }

        if (heavy && this.bigContentView != null) {
            that.bigContentView = this.bigContentView.clone();
        }

        if (heavy && this.headsUpContentView != null) {
            that.headsUpContentView = this.headsUpContentView.clone();
        }

        that.visibility = this.visibility;

        if (this.publicVersion != null) {
            that.publicVersion = new Notification();
            this.publicVersion.cloneInto(that.publicVersion, heavy);
        }

        that.color = this.color;

        if (!heavy) {
            that.lightenPayload(); // will clean out extras
        }
    
public intdescribeContents()

        return 0;
    
public java.lang.StringgetGroup()
Get the key used to group this notification into a cluster or stack with other notifications on devices which support such rendering.


                               
       
        return mGroupKey;
    
private static android.app.Notification[]getNotificationArrayFromBundle(android.os.Bundle bundle, java.lang.String key)
Get an array of Notification objects from a parcelable array bundle field. Update the bundle to have a typed array so fetches in the future don't need to do an array copy.

        Parcelable[] array = bundle.getParcelableArray(key);
        if (array instanceof Notification[] || array == null) {
            return (Notification[]) array;
        }
        Notification[] typedArray = Arrays.copyOf(array, array.length,
                Notification[].class);
        bundle.putParcelableArray(key, typedArray);
        return typedArray;
    
public java.lang.StringgetSortKey()
Get 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 {@link Builder#setGroup}.

see
String#compareTo(String)

        return mSortKey;
    
public booleanisGroupChild()

hide

        return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) == 0;
    
public booleanisGroupSummary()

hide

        return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) != 0;
    
public booleanisValid()

hide

        // Would like to check for icon!=0 here, too, but NotificationManagerService accepts that
        // for legacy reasons.
        return contentView != null || extras.getBoolean(Builder.EXTRA_REBUILD_CONTENT_VIEW);
    
public final voidlightenPayload()
Removes heavyweight parts of the Notification object for archival or for sending to listeners when the full contents are not necessary.

hide

        tickerView = null;
        contentView = null;
        bigContentView = null;
        headsUpContentView = null;
        largeIcon = null;
        if (extras != null) {
            extras.remove(Notification.EXTRA_LARGE_ICON);
            extras.remove(Notification.EXTRA_LARGE_ICON_BIG);
            extras.remove(Notification.EXTRA_PICTURE);
            extras.remove(Notification.EXTRA_BIG_TEXT);
            // Prevent light notifications from being rebuilt.
            extras.remove(Builder.EXTRA_NEEDS_REBUILD);
        }
    
public static java.lang.CharSequencesafeCharSequence(java.lang.CharSequence cs)
Make sure this CharSequence is safe to put into a bundle, which basically means it had better not be some custom Parcelable implementation.

hide

        if (cs == null) return cs;
        if (cs.length() > MAX_CHARSEQUENCE_LENGTH) {
            cs = cs.subSequence(0, MAX_CHARSEQUENCE_LENGTH);
        }
        if (cs instanceof Parcelable) {
            Log.e(TAG, "warning: " + cs.getClass().getCanonicalName()
                    + " instance is a custom Parcelable and not allowed in Notification");
            return cs.toString();
        }

        return cs;
    
public voidsetLatestEventInfo(android.content.Context context, java.lang.CharSequence contentTitle, java.lang.CharSequence contentText, PendingIntent contentIntent)
Sets the {@link #contentView} field to be a view with the standard "Latest Event" layout.

Uses the {@link #icon} and {@link #when} fields to set the icon and time fields in the view.

param
context The context for your application / activity.
param
contentTitle The title that goes in the expanded entry.
param
contentText The text that goes in the expanded entry.
param
contentIntent The intent to launch when the user clicks the expanded notification. 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.
deprecated
Use {@link Builder} instead.


                                                                                                                               
    
       
                  
        Notification.Builder builder = new Notification.Builder(context);

        // First, ensure that key pieces of information that may have been set directly
        // are preserved
        builder.setWhen(this.when);
        builder.setSmallIcon(this.icon);
        builder.setPriority(this.priority);
        builder.setTicker(this.tickerText);
        builder.setNumber(this.number);
        builder.setColor(this.color);
        builder.mFlags = this.flags;
        builder.setSound(this.sound, this.audioStreamType);
        builder.setDefaults(this.defaults);
        builder.setVibrate(this.vibrate);

        // now apply the latestEventInfo fields
        if (contentTitle != null) {
            builder.setContentTitle(contentTitle);
        }
        if (contentText != null) {
            builder.setContentText(contentText);
        }
        builder.setContentIntent(contentIntent);
        builder.buildInto(this);
    
public java.lang.StringtoString()

        StringBuilder sb = new StringBuilder();
        sb.append("Notification(pri=");
        sb.append(priority);
        sb.append(" contentView=");
        if (contentView != null) {
            sb.append(contentView.getPackage());
            sb.append("/0x");
            sb.append(Integer.toHexString(contentView.getLayoutId()));
        } else {
            sb.append("null");
        }
        sb.append(" vibrate=");
        if ((this.defaults & DEFAULT_VIBRATE) != 0) {
            sb.append("default");
        } else if (this.vibrate != null) {
            int N = this.vibrate.length-1;
            sb.append("[");
            for (int i=0; i<N; i++) {
                sb.append(this.vibrate[i]);
                sb.append(',");
            }
            if (N != -1) {
                sb.append(this.vibrate[N]);
            }
            sb.append("]");
        } else {
            sb.append("null");
        }
        sb.append(" sound=");
        if ((this.defaults & DEFAULT_SOUND) != 0) {
            sb.append("default");
        } else if (this.sound != null) {
            sb.append(this.sound.toString());
        } else {
            sb.append("null");
        }
        sb.append(" defaults=0x");
        sb.append(Integer.toHexString(this.defaults));
        sb.append(" flags=0x");
        sb.append(Integer.toHexString(this.flags));
        sb.append(String.format(" color=0x%08x", this.color));
        if (this.category != null) {
            sb.append(" category=");
            sb.append(this.category);
        }
        if (this.mGroupKey != null) {
            sb.append(" groupKey=");
            sb.append(this.mGroupKey);
        }
        if (this.mSortKey != null) {
            sb.append(" sortKey=");
            sb.append(this.mSortKey);
        }
        if (actions != null) {
            sb.append(" actions=");
            sb.append(actions.length);
        }
        sb.append(" vis=");
        sb.append(visibilityToString(this.visibility));
        if (this.publicVersion != null) {
            sb.append(" publicVersion=");
            sb.append(publicVersion.toString());
        }
        sb.append(")");
        return sb.toString();
    
public static java.lang.StringvisibilityToString(int vis)
{@hide}

        switch (vis) {
            case VISIBILITY_PRIVATE:
                return "PRIVATE";
            case VISIBILITY_PUBLIC:
                return "PUBLIC";
            case VISIBILITY_SECRET:
                return "SECRET";
            default:
                return "UNKNOWN(" + String.valueOf(vis) + ")";
        }
    
public voidwriteToParcel(android.os.Parcel parcel, int flags)
Flatten this notification from a parcel.

        parcel.writeInt(1);

        parcel.writeLong(when);
        parcel.writeInt(icon);
        parcel.writeInt(number);
        if (contentIntent != null) {
            parcel.writeInt(1);
            contentIntent.writeToParcel(parcel, 0);
        } else {
            parcel.writeInt(0);
        }
        if (deleteIntent != null) {
            parcel.writeInt(1);
            deleteIntent.writeToParcel(parcel, 0);
        } else {
            parcel.writeInt(0);
        }
        if (tickerText != null) {
            parcel.writeInt(1);
            TextUtils.writeToParcel(tickerText, parcel, flags);
        } else {
            parcel.writeInt(0);
        }
        if (tickerView != null) {
            parcel.writeInt(1);
            tickerView.writeToParcel(parcel, 0);
        } else {
            parcel.writeInt(0);
        }
        if (contentView != null) {
            parcel.writeInt(1);
            contentView.writeToParcel(parcel, 0);
        } else {
            parcel.writeInt(0);
        }
        if (largeIcon != null) {
            parcel.writeInt(1);
            largeIcon.writeToParcel(parcel, 0);
        } else {
            parcel.writeInt(0);
        }

        parcel.writeInt(defaults);
        parcel.writeInt(this.flags);

        if (sound != null) {
            parcel.writeInt(1);
            sound.writeToParcel(parcel, 0);
        } else {
            parcel.writeInt(0);
        }
        parcel.writeInt(audioStreamType);

        if (audioAttributes != null) {
            parcel.writeInt(1);
            audioAttributes.writeToParcel(parcel, 0);
        } else {
            parcel.writeInt(0);
        }

        parcel.writeLongArray(vibrate);
        parcel.writeInt(ledARGB);
        parcel.writeInt(ledOnMS);
        parcel.writeInt(ledOffMS);
        parcel.writeInt(iconLevel);

        if (fullScreenIntent != null) {
            parcel.writeInt(1);
            fullScreenIntent.writeToParcel(parcel, 0);
        } else {
            parcel.writeInt(0);
        }

        parcel.writeInt(priority);

        parcel.writeString(category);

        parcel.writeString(mGroupKey);

        parcel.writeString(mSortKey);

        parcel.writeBundle(extras); // null ok

        parcel.writeTypedArray(actions, 0); // null ok

        if (bigContentView != null) {
            parcel.writeInt(1);
            bigContentView.writeToParcel(parcel, 0);
        } else {
            parcel.writeInt(0);
        }

        if (headsUpContentView != null) {
            parcel.writeInt(1);
            headsUpContentView.writeToParcel(parcel, 0);
        } else {
            parcel.writeInt(0);
        }

        parcel.writeInt(visibility);

        if (publicVersion != null) {
            parcel.writeInt(1);
            publicVersion.writeToParcel(parcel, 0);
        } else {
            parcel.writeInt(0);
        }

        parcel.writeInt(color);