public final class Action


An actionable entry that is returned as part of the android.service.credentials.BeginGetCredentialResponse, and then shown on the user selector under a separate category of 'Actions'. An action entry is expected to navigate the user to an activity belonging to the credential provider, and finally result in a androidx.credentials.GetCredentialResponse.

When selected, the associated PendingIntent is invoked to launch a provider controlled activity. The activity invoked due to this pending intent will contain the android.service.credentials.BeginGetCredentialRequest as part of the intent extras. Providers must use PendingIntentHandler.retrieveBeginGetCredentialRequest to get the request.

When the user is done interacting with the activity and the provider has a credential to return, provider must call android.app.Activity.setResult with the result code as android.app.Activity.RESULT_OK, and the android.content.Intent data that has been prepared by setting androidx.credentials.GetCredentialResponse using PendingIntentHandler.setGetCredentialResponse, or by setting androidx.credentials.exceptions.GetCredentialException using PendingIntentHandler.setGetCredentialException before ending the activity. If the provider does not have a credential, or an exception to return, provider must call android.app.Activity.setResult with the result code as android.app.Activity.RESULT_CANCELED. Setting the result code to android.app.Activity.RESULT_CANCELED will re-surface the selector.

Examples of Action entries include an entry that is titled 'Add a new Password', and navigates to the 'add password' page of the credential provider app, or an entry that is titled 'Manage Credentials' and navigates to a particular page that lists all credentials, where the user may end up selecting a credential that the provider can then return.

See also
BeginGetCredentialResponse

for usage.

Summary

Nested types

public final class Action.Builder

A builder for Action

Public constructors

Action(
    @NonNull CharSequence title,
    @NonNull PendingIntent pendingIntent,
    CharSequence subtitle
)

constructs an instance of Action

Public methods

static final Action

Converts a framework android.service.credentials.Action class to a Jetpack Action class

final @NonNull PendingIntent

the PendingIntent that will get invoked when the user selects this entry, must be created with a unique request code per entry, with flag PendingIntent.FLAG_MUTABLE to allow the Android system to attach the final request, and NOT with flag PendingIntent.FLAG_ONE_SHOT as it can be invoked multiple times

final CharSequence

the optional subtitle that is displayed on the entry

final @NonNull CharSequence

the title of the entry

Public constructors

Action

Added in 1.2.0
public Action(
    @NonNull CharSequence title,
    @NonNull PendingIntent pendingIntent,
    CharSequence subtitle
)

constructs an instance of Action

Parameters
@NonNull CharSequence title

the title of the entry

@NonNull PendingIntent pendingIntent

the PendingIntent that will get invoked when the user selects this entry, must be created with a unique request code per entry, with flag PendingIntent.FLAG_MUTABLE to allow the Android system to attach the final request, and NOT with flag PendingIntent.FLAG_ONE_SHOT as it can be invoked multiple times

CharSequence subtitle

the optional subtitle that is displayed on the entry

Public methods

fromAction

Added in 1.3.0-alpha03
public static final Action fromAction(@NonNull Action action)

Converts a framework android.service.credentials.Action class to a Jetpack Action class

Note that this API is not needed in a general credential retrieval flow that is implemented using this jetpack library, where you are only required to construct an instance of Action to populate the BeginGetCredentialResponse, along with setting other entries.

Parameters
@NonNull Action action

the instance of framework action class to be converted

getPendingIntent

Added in 1.2.0
public final @NonNull PendingIntent getPendingIntent()

the PendingIntent that will get invoked when the user selects this entry, must be created with a unique request code per entry, with flag PendingIntent.FLAG_MUTABLE to allow the Android system to attach the final request, and NOT with flag PendingIntent.FLAG_ONE_SHOT as it can be invoked multiple times

getSubtitle

Added in 1.2.0
public final CharSequence getSubtitle()

the optional subtitle that is displayed on the entry

getTitle

Added in 1.2.0
public final @NonNull CharSequence getTitle()

the title of the entry