public final class

NotificationCompat.Action.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.core.app.NotificationCompat.Action.Builder

Overview

Builder class for NotificationCompat.Action objects.

Summary

Constructors
publicBuilder(IconCompat icon, java.lang.CharSequence title, PendingIntent intent)

Construct a new builder for NotificationCompat.Action object.

publicBuilder(int icon, java.lang.CharSequence title, PendingIntent intent)

Construct a new builder for NotificationCompat.Action object.

publicBuilder(NotificationCompat.Action action)

Construct a new builder for NotificationCompat.Action object using the fields from an NotificationCompat.Action.

Methods
public NotificationCompat.Action.BuilderaddExtras(Bundle extras)

Merge additional metadata into this builder.

public NotificationCompat.Action.BuilderaddRemoteInput(RemoteInput remoteInput)

Add an input to be collected from the user when this action is sent.

public NotificationCompat.Actionbuild()

Combine all of the options that have been set and return a new NotificationCompat.Action object.

public NotificationCompat.Action.Builderextend(NotificationCompat.Action.Extender extender)

Apply an extender to this action builder.

public static NotificationCompat.Action.BuilderfromAndroidAction(Notification.Action action)

Creates a NotificationCompat.Builder from an .

public BundlegetExtras()

Get the metadata Bundle used by this Builder.

public NotificationCompat.Action.BuildersetAllowGeneratedReplies(boolean allowGeneratedReplies)

Set whether the platform should automatically generate possible replies to add to RemoteInput.getChoices().

public NotificationCompat.Action.BuildersetAuthenticationRequired(boolean authenticationRequired)

From API 31, sets whether the OS should only send this action's PendingIntent on an unlocked device.

public NotificationCompat.Action.BuildersetContextual(boolean isContextual)

Sets whether this NotificationCompat.Action is a contextual action, i.e.

public NotificationCompat.Action.BuildersetSemanticAction(int semanticAction)

Sets the NotificationCompat.Action.SemanticAction for this NotificationCompat.Action.

public NotificationCompat.Action.BuildersetShowsUserInterface(boolean showsUserInterface)

Set whether or not this NotificationCompat.Action's PendingIntent will open a user interface.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder(IconCompat icon, java.lang.CharSequence title, PendingIntent intent)

Construct a new builder for NotificationCompat.Action object.

Note: For devices running an Android version strictly lower than API level 23 this constructor only supports resource-ID based IconCompat objects.

Parameters:

icon: icon to show for this action
title: the title of the action
intent: the PendingIntent to fire when users trigger this action

public Builder(int icon, java.lang.CharSequence title, PendingIntent intent)

Construct a new builder for NotificationCompat.Action object.

Parameters:

icon: icon to show for this action
title: the title of the action
intent: the PendingIntent to fire when users trigger this action

public Builder(NotificationCompat.Action action)

Construct a new builder for NotificationCompat.Action object using the fields from an NotificationCompat.Action.

Parameters:

action: the action to read fields from.

Methods

public static NotificationCompat.Action.Builder fromAndroidAction(Notification.Action action)

Creates a NotificationCompat.Builder from an .

public NotificationCompat.Action.Builder addExtras(Bundle extras)

Merge additional metadata into this builder.

Values within the Bundle will replace existing extras values in this Builder.

See also: NotificationCompat.Action.getExtras()

public Bundle getExtras()

Get the metadata Bundle used by this Builder.

The returned Bundle is shared with this Builder.

public NotificationCompat.Action.Builder addRemoteInput(RemoteInput remoteInput)

Add an input to be collected from the user when this action is sent. Response values can be retrieved from the fired intent by using the RemoteInput.getResultsFromIntent(Intent) function.

Parameters:

remoteInput: a RemoteInput to add to the action

Returns:

this object for method chaining

public NotificationCompat.Action.Builder setAllowGeneratedReplies(boolean allowGeneratedReplies)

Set whether the platform should automatically generate possible replies to add to RemoteInput.getChoices(). If the NotificationCompat.Action doesn't have a RemoteInput, this has no effect.

Parameters:

allowGeneratedReplies: true to allow generated replies, false otherwise

Returns:

this object for method chaining The default value is true

public NotificationCompat.Action.Builder setSemanticAction(int semanticAction)

Sets the NotificationCompat.Action.SemanticAction for this NotificationCompat.Action. A NotificationCompat.Action.SemanticAction denotes what an NotificationCompat.Action's PendingIntent will do (eg. reply, mark as read, delete, etc).

Parameters:

semanticAction: a NotificationCompat.Action.SemanticAction defined within NotificationCompat.Action with SEMANTIC_ACTION_ prefixes

Returns:

this object for method chaining

public NotificationCompat.Action.Builder setContextual(boolean isContextual)

Sets whether this NotificationCompat.Action 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.

public NotificationCompat.Action.Builder setAuthenticationRequired(boolean authenticationRequired)

From API 31, sets whether the OS should only send this action's PendingIntent on an unlocked device. If this is true and the device is locked when the action is invoked, the OS will show the keyguard and require successful authentication before invoking the intent. If this is false and the device is locked, the OS will decide whether authentication should be required.

public NotificationCompat.Action.Builder setShowsUserInterface(boolean showsUserInterface)

Set whether or not this NotificationCompat.Action's PendingIntent will open a user interface.

Parameters:

showsUserInterface: true if this NotificationCompat.Action's PendingIntent will open a user interface, otherwise false

Returns:

this object for method chaining The default value is true

Apply an extender to this action builder. Extenders may be used to add metadata or change options on this builder.

Combine all of the options that have been set and return a new NotificationCompat.Action object.

Returns:

the built action