NotificationCompat.Action
public class NotificationCompat.Action
Structure to encapsulate a named action that can be shown as part of this notification. It must include an icon, a label, and a PendingIntent to be fired when the action is selected by the user. Action buttons won't appear on platforms prior to Android JELLY_BEAN.
As of Android N, action button icons will not be displayed on action buttons, but are still required and are available to notification listeners, which may display them in other contexts, for example on a wearable device.
Apps should use addAction or addAction to attach actions.
Summary
Nested types |
|---|
public final class NotificationCompat.Action.BuilderBuilder class for |
public interface NotificationCompat.Action.ExtenderExtender interface for use with |
@IntDef(value = )Provides meaning to an |
public final class NotificationCompat.Action.WearableExtender implements NotificationCompat.Action.ExtenderWearable extender for notification actions. |
Constants |
|
|---|---|
static final int |
EMPHASIS_AUTO = 0The action’s visual emphasis is generally the default, or may be automatically determined by the system based on context. |
static final int |
EMPHASIS_PRIMARY = 1The action’s visual emphasis may indicate that this action is more important than others. |
static final int |
The action’s visual emphasis may indicate that this action is less important than others. |
static final int |
|
static final int |
SEMANTIC_ACTION_CALL = 10
|
static final int |
|
static final int |
|
static final int |
|
static final int |
|
static final int |
|
static final int |
|
static final int |
SEMANTIC_ACTION_PLAY = 13
|
static final int |
|
static final int |
SEMANTIC_ACTION_STOP = 15
|
static final int |
|
static final int |
|
static final int |
|
static final int |
STYLE_AUTO = 0The action can be presented with the best form for the content and context. |
static final int |
The action is best represented by a combo of the icon and text. |
static final int |
STYLE_ICON_ONLY = 3The action is best represented by only its icon. |
static final int |
STYLE_TEXT_ONLY = 1The action is best represented by only the text (its |
Public fields |
|
|---|---|
@Nullable PendingIntent |
Intent to send when the user invokes this action. |
int |
This field is deprecated. Use |
@Nullable CharSequence |
Title of the action. |
Public constructors |
|---|
Action(Note: For devices running an Android version strictly lower than API level 23 this constructor only supports resource-ID based IconCompat objects. |
Action( |
Public methods |
|
|---|---|
@Nullable PendingIntent |
|
boolean |
Return whether the platform should automatically generate possible replies for this |
@Nullable RemoteInput[] |
Get the list of inputs to be collected from the user that ONLY accept data when this action is sent. |
int |
Returns the app’s hint about the importance of this action relative to others in this notification. |
@NonNull Bundle |
Get additional metadata carried around with this Action. |
int |
This method is deprecated. use |
@Nullable IconCompat |
Return the icon associated with this Action. |
@Nullable RemoteInput[] |
Get the list of inputs to be collected from the user when this action is sent. |
int |
Returns the |
boolean |
Return whether or not triggering this |
int |
Returns the app’s hint about the preferred visual style of this action. |
@Nullable CharSequence |
getTitle() |
boolean |
Returns whether the OS should only send this action's |
boolean |
Returns whether this is a contextual Action, i.e. whether the action is dependent on the notification message body. |
Constants
EMPHASIS_AUTO
public static final int EMPHASIS_AUTO = 0
The action’s visual emphasis is generally the default, or may be automatically determined by the system based on context.
EMPHASIS_PRIMARY
public static final int EMPHASIS_PRIMARY = 1
The action’s visual emphasis may indicate that this action is more important than others.
EMPHASIS_SECONDARY
public static final int EMPHASIS_SECONDARY = 2
The action’s visual emphasis may indicate that this action is less important than others.
SEMANTIC_ACTION_ARCHIVE
public static final int SEMANTIC_ACTION_ARCHIVE = 5
SemanticAction: Archive the content associated with the notification. This could mean archiving an email, message, etc.
SEMANTIC_ACTION_CALL
public static final int SEMANTIC_ACTION_CALL = 10
SemanticAction: Call a contact, group, etc.
SEMANTIC_ACTION_DELETE
public static final int SEMANTIC_ACTION_DELETE = 4
SemanticAction: Delete the content associated with the notification. This could mean deleting an email, message, etc.
SEMANTIC_ACTION_MARK_AS_READ
public static final int SEMANTIC_ACTION_MARK_AS_READ = 2
SemanticAction: Mark content as read.
SEMANTIC_ACTION_MARK_AS_UNREAD
public static final int SEMANTIC_ACTION_MARK_AS_UNREAD = 3
SemanticAction: Mark content as unread.
SEMANTIC_ACTION_MUTE
public static final int SEMANTIC_ACTION_MUTE = 6
SemanticAction: Mute the content associated with the notification. This could mean silencing a conversation or currently playing media.
SEMANTIC_ACTION_NONE
public static final int SEMANTIC_ACTION_NONE = 0
SemanticAction: No semantic action defined.
SEMANTIC_ACTION_PAUSE
public static final int SEMANTIC_ACTION_PAUSE = 14
SemanticAction: Pause the content associated with the notification. This could mean pausing media playback, pausing a running timer, etc.
SEMANTIC_ACTION_PLAY
public static final int SEMANTIC_ACTION_PLAY = 13
SemanticAction: Start (or continue previously paused) content associated with the notification. This could mean starting media playback, resuming a paused timer, etc.
SEMANTIC_ACTION_REPLY
public static final int SEMANTIC_ACTION_REPLY = 1
SemanticAction: Reply to a conversation, chat, group, or wherever replies may be appropriate.
SEMANTIC_ACTION_STOP
public static final int SEMANTIC_ACTION_STOP = 15
SemanticAction: Stop the content associated with the notification. This could mean stopping media playback, resetting a timer, etc. It is implied that a follow-up SEMANTIC_ACTION_PLAY would restart from the beginning, or may not be offered at all.
SEMANTIC_ACTION_THUMBS_DOWN
public static final int SEMANTIC_ACTION_THUMBS_DOWN = 9
SemanticAction: Mark content with a thumbs down.
SEMANTIC_ACTION_THUMBS_UP
public static final int SEMANTIC_ACTION_THUMBS_UP = 8
SemanticAction: Mark content with a thumbs up.
SEMANTIC_ACTION_UNMUTE
public static final int SEMANTIC_ACTION_UNMUTE = 7
SemanticAction: Unmute the content associated with the notification. This could mean un-silencing a conversation or currently playing media.
STYLE_AUTO
public static final int STYLE_AUTO = 0
The action can be presented with the best form for the content and context.
STYLE_ICON_AND_TEXT
public static final int STYLE_ICON_AND_TEXT = 2
The action is best represented by a combo of the icon and text.
STYLE_ICON_ONLY
public static final int STYLE_ICON_ONLY = 3
The action is best represented by only its icon.
STYLE_TEXT_ONLY
public static final int STYLE_TEXT_ONLY = 1
The action is best represented by only the text (its title).
Public fields
actionIntent
public @Nullable PendingIntent actionIntent
Intent to send when the user invokes this action. May be null, in which case the action may be rendered in a disabled presentation.
Public constructors
Action
public Action(
@Nullable IconCompat icon,
@Nullable CharSequence title,
@Nullable PendingIntent intent
)
Note: For devices running an Android version strictly lower than API level 23 this constructor only supports resource-ID based IconCompat objects.
Action
public Action(
int icon,
@Nullable CharSequence title,
@Nullable PendingIntent intent
)
Public methods
getAllowGeneratedReplies
public boolean getAllowGeneratedReplies()
Return whether the platform should automatically generate possible replies for this Action
getDataOnlyRemoteInputs
public @Nullable RemoteInput[] getDataOnlyRemoteInputs()
Get the list of inputs to be collected from the user that ONLY accept data when this action is sent. These remote inputs are guaranteed to return true on a call to isDataOnly.
May return null if no data-only remote inputs were added.
This method exists so that legacy RemoteInput collectors that pre-date the addition of non-textual RemoteInputs do not access these remote inputs.
getEmphasisHint
public int getEmphasisHint()
Returns the app’s hint about the importance of this action relative to others in this notification.
getExtras
public @NonNull Bundle getExtras()
Get additional metadata carried around with this Action.
getIconCompat
public @Nullable IconCompat getIconCompat()
Return the icon associated with this Action.
getRemoteInputs
public @Nullable RemoteInput[] getRemoteInputs()
Get the list of inputs to be collected from the user when this action is sent. May return null if no remote inputs were added. Only returns inputs which accept a text input. For inputs which only accept data use getDataOnlyRemoteInputs.
getSemanticAction
@NotificationCompat.Action.SemanticAction
public int getSemanticAction()
Returns the SemanticAction associated with this Action. A SemanticAction denotes what an Action's PendingIntent will do (eg. reply, mark as read, delete, etc).
getShowsUserInterface
public boolean getShowsUserInterface()
Return whether or not triggering this Action's PendingIntent will open a user interface.
getStyleHint
public int getStyleHint()
Returns the app’s hint about the preferred visual style of this action.
isAuthenticationRequired
public boolean isAuthenticationRequired()
Returns whether the OS should only send this action's PendingIntent on an unlocked device. If the device is locked when the action is invoked, the OS should show the keyguard and require successful authentication before invoking the intent.
isContextual
public boolean isContextual()
Returns whether this is a contextual Action, i.e. whether the action is dependent on the notification message body. An example of a contextual action could be an action opening a map application with an address shown in the notification.