class IntentHandler


IntentHandler 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 intents from the import flow.

The Provider Selector UI Activity will display a list of ExportEntry and create a launch intent that corresponds to the provider's activity. More info on how the intent is constructed for the provider activity can be found in the documentation of ProviderEventsManager.registerExport.

When user selects one of the ExportEntry, 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.

Summary

Public companion functions

ProviderImportCredentialsRequest?

Extracts the ProviderImportCredentialsRequest from the Intent that started the provider's exporting Activity.

Unit

Sets the androidx.credentials.providerevents.exception.ImportCredentialsException if an error is encountered when the provider application is invoked to fulfill the credential import request.

Unit
setImportCredentialsResponse(
    context: Context,
    uri: Uri,
    intent: Intent,
    response: ImportCredentialsResponse
)

Writes the successful ImportCredentialsResponse to the content Uri provided by the importing framework.

Public constructors

Public companion functions

retrieveProviderImportCredentialsRequest

Added in 1.0.0-alpha03
fun retrieveProviderImportCredentialsRequest(intent: Intent): ProviderImportCredentialsRequest?

Extracts the ProviderImportCredentialsRequest from the Intent that started the provider's exporting Activity.

This should be called in your activity's onCreate method to retrieve the details of the import request, including the calling app's information and the Uri for writing the response back.

Parameters
intent: Intent

the Intent received by the provider's exporting Activity.

Returns
ProviderImportCredentialsRequest?

the parsed ProviderImportCredentialsRequest, or null if the intent is missing required data.

setImportCredentialsException

Added in 1.0.0-alpha03
fun setImportCredentialsException(
    intent: Intent,
    exception: ImportCredentialsException
): Unit

Sets the androidx.credentials.providerevents.exception.ImportCredentialsException if an error is encountered when the provider application is invoked to fulfill the credential import request.

Note: After populating the intent with an exception, the provider must still use [Activity.RESULT_OK] when calling [Activity.setResult]. The system will inspect the `Intent` data to determine if an error occurred and return the exception back to the caller. If both a valid response and an exception are found, then the exception will be returned to the caller.

Parameters
intent: Intent

the result Intent to which the exception will be added.

exception: ImportCredentialsException

the exception to be returned to the importer.

setImportCredentialsResponse

Added in 1.0.0-alpha03
fun setImportCredentialsResponse(
    context: Context,
    uri: Uri,
    intent: Intent,
    response: ImportCredentialsResponse
): Unit

Writes the successful ImportCredentialsResponse to the content Uri provided by the importing framework. The 'responseJson' of the successful ImportCredentialsResponse will be written to the content 'Uri' to bypass the binder transaction limit. For any additional parameters of the ImportCredentialsResponse will be written to the intent that is passed in. This intent and Activity.RESULT_OK should be set as the result of the activity that was invoked for credential transfer.

Parameters
context: Context

the context

uri: Uri

the uri that was provided by the importer

intent: Intent

the intent to be set on the result of the Activity

response: ImportCredentialsResponse

the response to be passed to the importer

Public constructors

IntentHandler

Added in 1.0.0-alpha03
IntentHandler()