PendingIntentHandler


@RequiresApi(value = 23)
public final class PendingIntentHandler


PendingIntentHandler to be used by credential providers to extract requests from a given intent, or to set back a response or an exception to a given intent while dealing with activities invoked by pending intents set on a CreateEntry for the create flow, or on a CredentialEntry, AuthenticationAction, Action, or a RemoteEntry set for a get flow.

When user selects one of the entries mentioned above, the credential provider's corresponding activity is invoked. The intent associated with this activity must be extracted and passed into the utils in this class to extract the required requests.

When user interaction is complete, credential providers must set the activity result by calling android.app.Activity.setResult by setting an appropriate result code and data of type Intent. This data should also be prepared by using the utils in this class to populate the required response/exception.

See extension functions for Intent in IntentHandlerConverters.kt to help test intents that are set on pending intents in different entry classes.

Summary

Public constructors

Public methods

static final BeginGetCredentialRequest

Extracts the BeginGetCredentialRequest from the provider's PendingIntent invoked by the Android system when the user selects an AuthenticationAction.

static final ProviderCreateCredentialRequest

Extracts the ProviderCreateCredentialRequest from the provider's PendingIntent invoked by the Android system.

static final ProviderGetCredentialRequest

Extracts the ProviderGetCredentialRequest from the provider's PendingIntent invoked by the Android system, when the user selects a CredentialEntry.

static final void

Sets the android.service.credentials.BeginGetCredentialResponse on the intent passed in.

static final void

Sets the androidx.credentials.exceptions.CreateCredentialException if an error is encountered during the final phase of the create credential flow.

static final void

Sets the CreateCredentialResponse on the intent passed in.

static final void

Sets the androidx.credentials.exceptions.GetCredentialException if an error is encountered during the final phase of the get credential flow.

static final void

Sets the android.credentials.GetCredentialResponse on the intent passed in.

Public constructors

PendingIntentHandler

Added in 1.2.0
public PendingIntentHandler()

Public methods

retrieveBeginGetCredentialRequest

Added in 1.2.0
public static final BeginGetCredentialRequest retrieveBeginGetCredentialRequest(@NonNull Intent intent)

Extracts the BeginGetCredentialRequest from the provider's PendingIntent invoked by the Android system when the user selects an AuthenticationAction.

Parameters
@NonNull Intent intent

the intent associated with the Activity invoked through the PendingIntent

retrieveProviderCreateCredentialRequest

Added in 1.2.0
public static final ProviderCreateCredentialRequest retrieveProviderCreateCredentialRequest(@NonNull Intent intent)

Extracts the ProviderCreateCredentialRequest from the provider's PendingIntent invoked by the Android system.

Parameters
@NonNull Intent intent

the intent associated with the Activity invoked through the PendingIntent

retrieveProviderGetCredentialRequest

Added in 1.2.0
public static final ProviderGetCredentialRequest retrieveProviderGetCredentialRequest(@NonNull Intent intent)

Extracts the ProviderGetCredentialRequest from the provider's PendingIntent invoked by the Android system, when the user selects a CredentialEntry.

Parameters
@NonNull Intent intent

the intent associated with the Activity invoked through the PendingIntent

setBeginGetCredentialResponse

Added in 1.2.0
public static final void setBeginGetCredentialResponse(
    @NonNull Intent intent,
    @NonNull BeginGetCredentialResponse response
)

Sets the android.service.credentials.BeginGetCredentialResponse on the intent passed in. This intent is then set as the data associated with the result of the activity invoked by the PendingIntent, set on an AuthenticationAction. The intent is set using the Activity.setResult method that takes in the intent, as well as a result code.

A credential provider must set the result code to Activity.RESULT_OK if a valid response, or a valid exception is being set as part of the data to the result. However, if the credential provider is unable to resolve to a valid response or exception, the result code must be set to Activity.RESULT_CANCELED. Note that setting the result code to Activity.RESULT_CANCELED will re-surface the account selection bottom sheet that displayed the original CredentialEntry, hence allowing the user to re-select.

Parameters
@NonNull Intent intent

the intent to be set on the result of the Activity invoked through the PendingIntent

@NonNull BeginGetCredentialResponse response

the response to be set as an extra on the intent

setCreateCredentialException

Added in 1.2.0
public static final void setCreateCredentialException(
    @NonNull Intent intent,
    @NonNull CreateCredentialException exception
)

Sets the androidx.credentials.exceptions.CreateCredentialException if an error is encountered during the final phase of the create credential flow.

A credential provider service returns a list of CreateEntry as part of the BeginCreateCredentialResponse to the query phase of the get-credential flow.

If the user selects one of these entries, the corresponding PendingIntent is fired and the provider's activity is invoked. If there is an error encountered during the lifetime of that activity, the provider must use this API to set an exception before finishing the activity.

The intent is set using the Activity.setResult method that takes in the intent, as well as a result code. A credential provider must set the result code to Activity.RESULT_OK if a valid credential, or a valid exception is being set as the data to the result. However, if the credential provider is unable to resolve to a valid response or exception, the result code must be set to Activity.RESULT_CANCELED.

Note that setting the result code to Activity.RESULT_CANCELED will re-surface the account selection bottom sheet that displayed the original CreateEntry, hence allowing the user to re-select.

Parameters
@NonNull Intent intent

the intent to be set on the result of the Activity invoked through the PendingIntent

@NonNull CreateCredentialException exception

the exception to be set as an extra to the intent

setCreateCredentialResponse

Added in 1.2.0
public static final void setCreateCredentialResponse(
    @NonNull Intent intent,
    @NonNull CreateCredentialResponse response
)

Sets the CreateCredentialResponse on the intent passed in. This intent is then set as the data associated with the result of the activity invoked by the PendingIntent set on a CreateEntry. The intent is set using the Activity.setResult method that takes in the intent, as well as a result code.

A credential provider must set the result code to Activity.RESULT_OK if a valid response, or a valid exception is being set as the data to the result. However, if the credential provider is unable to resolve to a valid response or exception, the result code must be set to Activity.RESULT_CANCELED. Note that setting the result code to Activity.RESULT_CANCELED will re-surface the account selection bottom sheet that displayed the original CredentialEntry, hence allowing the user to re-select.

Parameters
@NonNull Intent intent

the intent to be set on the result of the Activity invoked through the PendingIntent

@NonNull CreateCredentialResponse response

the response to be set as an extra on the intent

setGetCredentialException

Added in 1.2.0
public static final void setGetCredentialException(
    @NonNull Intent intent,
    @NonNull GetCredentialException exception
)

Sets the androidx.credentials.exceptions.GetCredentialException if an error is encountered during the final phase of the get credential flow.

A credential provider service returns a list of CredentialEntry as part of the BeginGetCredentialResponse to the query phase of the get-credential flow. If the user selects one of these entries, the corresponding PendingIntent is fired and the provider's activity is invoked. If there is an error encountered during the lifetime of that activity, the provider must use this API to set an exception on the given intent before finishing the activity in question.

The intent is set using the Activity.setResult method that takes in the intent, as well as a result code. A credential provider must set the result code to Activity.RESULT_OK if a valid credential, or a valid exception is being set as the data to the result. However, if the credential provider is unable to resolve to a valid response or exception, the result code must be set to Activity.RESULT_CANCELED.

Note that setting the result code to Activity.RESULT_CANCELED will re-surface the account selection bottom sheet that displayed the original CredentialEntry, hence allowing the user to re-select.

Parameters
@NonNull Intent intent

the intent to be set on the result of the Activity invoked through the PendingIntent

@NonNull GetCredentialException exception

the exception to be set as an extra to the intent

setGetCredentialResponse

Added in 1.2.0
public static final void setGetCredentialResponse(
    @NonNull Intent intent,
    @NonNull GetCredentialResponse response
)

Sets the android.credentials.GetCredentialResponse on the intent passed in. This intent is then set as the data associated with the result of the activity invoked by the PendingIntent, set on a CredentialEntry. The intent is set using the Activity.setResult method that takes in the intent, as well as a result code.

A credential provider must set the result code to Activity.RESULT_OK if a valid credential, or a valid exception is being set as the data to the result. However, if the credential provider is unable to resolve to a valid response or exception, the result code must be set to Activity.RESULT_CANCELED. Note that setting the result code to Activity.RESULT_CANCELED will re-surface the account selection bottom sheet that displayed the original CredentialEntry, hence allowing the user to re-select.

Parameters
@NonNull Intent intent

the intent to be set on the result of the Activity invoked through the PendingIntent

@NonNull GetCredentialResponse response

the response to be set as an extra on the intent