Public methods

addAction

Add an action to this notification. Actions are typically displayed by the system as a button adjacent to the notification content. Action buttons won't appear on platforms prior to Android 4.1. Action buttons depend on expanded notifications, which are only available in Android 4.1 and later. To ensure that an action button's functionality is always available, first implement the functionality in the android.app.Activity that starts when a user clicks the notification (see setContentIntent()), and then enhance the notification by implementing the same functionality with addAction().

addAction

Add an action to this notification. Actions are typically displayed by the system as a button adjacent to the notification content. Action buttons won't appear on platforms prior to Android 4.1. Action buttons depend on expanded notifications, which are only available in Android 4.1 and later. To ensure that an action button's functionality is always available, first implement the functionality in the android.app.Activity that starts when a user clicks the notification (see setContentIntent()), and then enhance the notification by implementing the same functionality with addAction().

addInvisibleAction

Add an invisible action to this notification. Invisible actions are never displayed by the system, but can be retrieved and used by other application listening to system notifications. Invisible actions are supported from Android 4.4.4 (API 20) and can be retrieved using NotificationCompat#getInvisibleActions(Notification).

addInvisibleAction

Add an invisible action to this notification. Invisible actions are never displayed by the system, but can be retrieved and used by other application listening to system notifications. Invisible actions are supported from Android 4.4.4 (API 20) and can be retrieved using NotificationCompat#getInvisibleActions(Notification).

The system will also attempt to resolve mailto: and tel: schema URIs. The path part of these URIs must exist in the contacts database, in the appropriate column, or the reference will be discarded as invalid. Telephone schema URIs will be resolved by android.provider.ContactsContract.PhoneLookup.

setAutoCancel

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 will be broadcast when the notification is canceled.

setBubbleMetadata

Sets the BubbleMetadata that will be used to display app content in a floating window over the existing foreground activity.

This data will be ignored unless the notification is posted to a channel that allows bubbles.

Notifications allowed to bubble that have valid bubble metadata will display in collapsed state outside of the notification shade on unlocked devices. When a user interacts with the collapsed state, the bubble intent will be invoked and displayed.

setCustomBigContentView

Supply custom RemoteViews to use instead of the platform template in the expanded form. This will override the expanded layout that would otherwise be constructed by this Builder object. No-op on versions prior to android.os.Build.VERSION_CODES#JELLY_BEAN.

setCustomHeadsUpContentView

Supply custom RemoteViews to use instead of the platform template in the heads up dialog. This will override the heads-up layout that would otherwise be constructed by this Builder object. No-op on versions prior to android.os.Build.VERSION_CODES#LOLLIPOP.

setDeleteIntent

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).

setFullScreenIntent

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.

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

setGroupAlertBehavior

Sets the group alert behavior for this notification. Use this method to mute this notification if alerts for this notification's group should be handled by a different notification. This is only applicable for notifications that belong to a group. This must be called on all notifications you want to mute. For example, if you want only the summary of your group to make noise, all children in the group should have the group alert behavior GROUP_ALERT_SUMMARY.

setGroupSummary

Set this notification to be 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 setGroup.

setLights

Set the argb value that you would like the LED on the device to blink, 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.

setPriority

Set the 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 sets a notification's priority based on various factors including the setPriority value. The effect may differ slightly on different platforms.

Parameters

pri

Int: Relative priority for this notification. Must be one of the priority constants defined by NotificationCompat. Acceptable values range from (-2) to (2).

setRemoteInputHistory

Set the remote input history. This should be set to the most recent inputs that have been sent through a RemoteInput of this Notification and cleared once the it is no longer relevant (e.g. for chat notifications once the other party has responded). The most recent input must be stored at the 0 index, the second most recent at the 1 index, etc. Note that the system will limit both how far back the inputs will be shown and how much of each individual input is shown.

Note: The reply text will only be shown on notifications that have least one action with a RemoteInput.

setSortKey

Set 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 Builder#setGroup.

setSubText

Set the third line of text in the platform notification template. Don't use if you're also using setProgress(int, int, boolean); they occupy the same location in the standard template. If the platform does not provide large-format notifications, this method has no effect. The third line of text only appears in expanded view.

setTicker

Sets the "ticker" text which is sent to accessibility services. Prior to Build.VERSION_CODES#LOLLIPOP, sets 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.

setUsesChronometer

Show the Notification#when field as a stopwatch. Instead of presenting when as a timestamp, the notification will show an automatically updating display of the minutes and seconds since when. Useful when showing an elapsed time (like an ongoing phone call).