PendingIntentHandler
@RequiresApi(value = 23)
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 companion functions
retrieveBeginGetCredentialRequest
fun retrieveBeginGetCredentialRequest(intent: Intent): BeginGetCredentialRequest?
Extracts the BeginGetCredentialRequest from the provider's PendingIntent invoked by the Android system when the user selects an AuthenticationAction.
| Parameters | |
|---|---|
intent: Intent |
the intent associated with the |
| Throws | |
|---|---|
kotlin.NullPointerException |
If |
retrieveProviderCreateCredentialRequest
fun retrieveProviderCreateCredentialRequest(intent: Intent): ProviderCreateCredentialRequest?
Extracts the ProviderCreateCredentialRequest from the provider's PendingIntent invoked by the Android system.
| Parameters | |
|---|---|
intent: Intent |
the intent associated with the |
| Throws | |
|---|---|
kotlin.NullPointerException |
If |
retrieveProviderGetCredentialRequest
fun retrieveProviderGetCredentialRequest(intent: Intent): ProviderGetCredentialRequest?
Extracts the ProviderGetCredentialRequest from the provider's PendingIntent invoked by the Android system, when the user selects a CredentialEntry.
| Parameters | |
|---|---|
intent: Intent |
the intent associated with the |
| Throws | |
|---|---|
kotlin.NullPointerException |
If |
setBeginGetCredentialResponse
fun setBeginGetCredentialResponse(
intent: Intent,
response: BeginGetCredentialResponse
): Unit
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 | |
|---|---|
intent: Intent |
the intent to be set on the result of the |
response: BeginGetCredentialResponse |
the response to be set as an extra on the |
| Throws | |
|---|---|
kotlin.NullPointerException |
setCreateCredentialException
fun setCreateCredentialException(
intent: Intent,
exception: CreateCredentialException
): Unit
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 | |
|---|---|
intent: Intent |
the intent to be set on the result of the |
exception: CreateCredentialException |
the exception to be set as an extra to the |
| Throws | |
|---|---|
kotlin.NullPointerException |
setCreateCredentialResponse
fun setCreateCredentialResponse(
intent: Intent,
response: CreateCredentialResponse
): Unit
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 | |
|---|---|
intent: Intent |
the intent to be set on the result of the |
response: CreateCredentialResponse |
the response to be set as an extra on the |
| Throws | |
|---|---|
kotlin.NullPointerException |
setGetCredentialException
fun setGetCredentialException(
intent: Intent,
exception: GetCredentialException
): Unit
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 | |
|---|---|
intent: Intent |
the intent to be set on the result of the |
exception: GetCredentialException |
the exception to be set as an extra to the |
| Throws | |
|---|---|
kotlin.NullPointerException |
setGetCredentialResponse
fun setGetCredentialResponse(intent: Intent, response: GetCredentialResponse): Unit
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 | |
|---|---|
intent: Intent |
the intent to be set on the result of the |
response: GetCredentialResponse |
the response to be set as an extra on the |
| Throws | |
|---|---|
kotlin.NullPointerException |