Notification.Action.Builder | API reference | Android Developers (original) (raw)
public static final class Notification.Action.Builderextends [Object](/reference/java/lang/Object) ``
Builder class for [Action](/reference/android/app/Notification.Action) objects.
Summary
| Public constructors |
|---|
| Builder(Notification.Action action) Construct a new builder for Action object using the fields from anAction. |
| Builder(Icon icon, CharSequence title, PendingIntent intent) Construct a new builder for Action object. |
| Builder(int icon, CharSequence title, PendingIntent intent) Construct a new builder for Action object. |
| Public methods | |
|---|---|
| Notification.Action.Builder | addExtras(Bundle extras) Merge additional metadata into this builder. |
| Notification.Action.Builder | addRemoteInput(RemoteInput remoteInput) Add an input to be collected from the user when this action is sent. |
| Notification.Action | build() Combine all of the options that have been set and return a new Action object. |
| Notification.Action.Builder | extend(Notification.Action.Extender extender) Apply an Extender to this action builder. |
| Bundle | getExtras() Get the metadata Bundle used by this Builder. |
| Notification.Action.Builder | setAllowGeneratedReplies(boolean allowGeneratedReplies) Set whether the platform should automatically generate possible replies to add toRemoteInput.getChoices(). |
| Notification.Action.Builder | setAuthenticationRequired(boolean authenticationRequired) Sets whether the OS should only send this action's PendingIntent on an unlocked device. |
| Notification.Action.Builder | setContextual(boolean isContextual) Sets whether this Action is a contextual action, i.e. |
| Notification.Action.Builder | setEmphasisHint(int emphasis) Sets a hint about the importance of this action relative to others in this notification. |
| Notification.Action.Builder | setSemanticAction(int semanticAction) Sets the SemanticAction for this Action. |
| Notification.Action.Builder | setStyleHint(int style) Sets a preferred visual style of this action. |
| Inherited methods |
|---|
| From class java.lang.Object Object clone() Creates and returns a copy of this object. boolean equals(Object obj) Indicates whether some other object is "equal to" this one. void finalize() Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. finalClass<?> getClass() Returns the runtime class of this Object. int hashCode() Returns a hash code value for the object. final void notify() Wakes up a single thread that is waiting on this object's monitor. final void notifyAll() Wakes up all threads that are waiting on this object's monitor. String toString() Returns a string representation of the object. final void wait(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. final void wait(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. final void wait() Causes the current thread to wait until it is awakened, typically by being notified or interrupted. |
Public constructors
Builder
public Builder (Notification.Action action)
Construct a new builder for [Action](/reference/android/app/Notification.Action) object using the fields from an[Action](/reference/android/app/Notification.Action).
| Parameters | |
|---|---|
| action | Notification.Action: the action to read fields from |
Builder
public Builder (Icon icon, CharSequence title, PendingIntent intent)
Construct a new builder for [Action](/reference/android/app/Notification.Action) object.
As of Android [Build.VERSION_CODES.S](/reference/android/os/Build.VERSION%5FCODES#S), apps targeting API level[Build.VERSION_CODES.S](/reference/android/os/Build.VERSION%5FCODES#S) or higher won't be able to start activities while processing broadcast receivers or services in response to notification action clicks. To launch an activity in those cases, provide a [PendingIntent](/reference/android/app/PendingIntent) for the activity itself.
How an Action is displayed, including whether the icon, text, or both are displayed or required, depends on where and how the action is used, and the[ERROR(Style/android.app.Notification.Action.Style Style)](/) applied to the Notification.
As of Android [Build.VERSION_CODES.N](/reference/android/os/Build.VERSION%5FCODES#N), action button icons will not be displayed on action buttons, but are still required and are available to [notification listeners](/reference/android/service/notification/NotificationListenerService), which may display them in other contexts, for example on a wearable device.
When the title is a [Spanned](/reference/android/text/Spanned), any colors set by a[ForegroundColorSpan](/reference/android/text/style/ForegroundColorSpan) or [TextAppearanceSpan](/reference/android/text/style/TextAppearanceSpan) may be removed or displayed with an altered in luminance to ensure proper contrast within the Notification.
| Parameters | |
|---|---|
| icon | Icon: icon to show for this action |
| title | CharSequence: the title of the action |
| intent | PendingIntent: the PendingIntent to fire when users trigger this action. May be null, in which case the action may be rendered in a disabled presentation by the system UI. |
Builder
public Builder (int icon, CharSequence title, PendingIntent intent)
Construct a new builder for [Action](/reference/android/app/Notification.Action) object.
As of Android [Build.VERSION_CODES.N](/reference/android/os/Build.VERSION%5FCODES#N), action button icons will not be displayed on action buttons, but are still required and are available to[notification listeners](/reference/android/service/notification/NotificationListenerService), which may display them in other contexts, for example on a wearable device.
| Parameters | |
|---|---|
| icon | int: icon to show for this action |
| title | CharSequence: the title of the action |
| intent | PendingIntent: the PendingIntent to fire when users trigger this action. May be null, in which case the action may be rendered in a disabled presentation by the system UI. |
Public methods
public Bundle getExtras ()
Get the metadata Bundle used by this Builder.
The returned Bundle is shared with this Builder.
| Returns | |
|---|---|
| Bundle | This value cannot be null. |
setAuthenticationRequired
public Notification.Action.Builder setAuthenticationRequired (boolean authenticationRequired)
Sets whether the OS should only send this action's [PendingIntent](/reference/android/app/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.
| Parameters | |
|---|---|
| authenticationRequired | boolean |
| Returns | |
|---|---|
| Notification.Action.Builder | This value cannot be null. |
setContextual
public Notification.Action.Builder setContextual (boolean isContextual)
Sets whether this [Action](/reference/android/app/Notification.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.
| Parameters | |
|---|---|
| isContextual | boolean |
| Returns | |
|---|---|
| Notification.Action.Builder | This value cannot be null. |