# IntentHandler

Artifact: [androidx.credentials.providerevents:providerevents](https://developer.android.com/jetpack/androidx/releases/credentials-providerevents) [View Source](https://cs.android.com/search?q=file:androidx/credentials/providerevents/IntentHandler.kt+class:androidx.credentials.providerevents.IntentHandler) Added in [1.0.0-beta01](https://developer.android.com/jetpack/androidx/releases/credentials-providerevents#1.0.0-beta01)

*** ** * ** ***


```
public final class IntentHandler
```

<br />

*** ** * ** ***

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 `https://developer.android.com/reference/androidx/credentials/providerevents/transfer/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 `https://developer.android.com/reference/androidx/credentials/providerevents/ProviderEventsManager#registerExport(androidx.credentials.providerevents.transfer.RegisterExportRequest)`.

When user selects one of the `https://developer.android.com/reference/androidx/credentials/providerevents/transfer/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 `https://developer.android.com/reference/android/app/Activity.html#setResult(int)` by setting an appropriate result code and data of type `https://developer.android.com/reference/android/content/Intent.html`. This data should also be prepared by using the utils in this class to populate the required response/exception.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/credentials/providerevents/IntentHandler#IntentHandler()()` |

| ### Public methods |
|---|---|
| `static final https://developer.android.com/reference/androidx/credentials/providerevents/transfer/ProviderImportCredentialsRequest` | `https://developer.android.com/reference/androidx/credentials/providerevents/IntentHandler#retrieveProviderImportCredentialsRequest(android.content.Intent)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Intent.html intent)` Extracts the `https://developer.android.com/reference/androidx/credentials/providerevents/transfer/ProviderImportCredentialsRequest` from the `https://developer.android.com/reference/android/content/Intent.html` that started the provider's exporting `https://developer.android.com/reference/android/app/Activity.html`. |
| `static final void` | `https://developer.android.com/reference/androidx/credentials/providerevents/IntentHandler#setImportCredentialsException(android.content.Intent,androidx.credentials.providerevents.exception.ImportCredentialsException)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Intent.html intent, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/providerevents/exception/ImportCredentialsException exception )` Sets the `https://developer.android.com/reference/androidx/credentials/providerevents/exception/ImportCredentialsException` if an error is encountered when the provider application is invoked to fulfill the credential import request. |
| `static final void` | `https://developer.android.com/reference/androidx/credentials/providerevents/IntentHandler#setImportCredentialsResponse(android.content.Context,android.net.Uri,android.content.Intent,androidx.credentials.providerevents.transfer.ImportCredentialsResponse)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/net/Uri.html uri, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Intent.html intent, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/providerevents/transfer/ImportCredentialsResponse response )` Writes the successful `https://developer.android.com/reference/androidx/credentials/providerevents/transfer/ImportCredentialsResponse` to the content `Uri` provided by the importing framework. |

## Public constructors

### IntentHandler

Added in [1.0.0-beta01](https://developer.android.com/jetpack/androidx/releases/credentials-providerevents#1.0.0-beta01)

```
public IntentHandler()
```

## Public methods

### retrieveProviderImportCredentialsRequest

Added in [1.0.0-beta01](https://developer.android.com/jetpack/androidx/releases/credentials-providerevents#1.0.0-beta01)

```
public static final ProviderImportCredentialsRequest retrieveProviderImportCredentialsRequest(@NonNull Intent intent)
```

Extracts the `https://developer.android.com/reference/androidx/credentials/providerevents/transfer/ProviderImportCredentialsRequest` from the `https://developer.android.com/reference/android/content/Intent.html` that started the provider's exporting `https://developer.android.com/reference/android/app/Activity.html`.

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 `https://developer.android.com/reference/android/net/Uri.html` for writing the response back.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Intent.html intent` | the `Intent` received by the provider's exporting `Activity`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/credentials/providerevents/transfer/ProviderImportCredentialsRequest` | the parsed `https://developer.android.com/reference/androidx/credentials/providerevents/transfer/ProviderImportCredentialsRequest`, or `null` if the intent is missing required data. |

### setImportCredentialsException

Added in [1.0.0-beta01](https://developer.android.com/jetpack/androidx/releases/credentials-providerevents#1.0.0-beta01)

```
public static final void setImportCredentialsException(
    @NonNull Intent intent,
    @NonNull ImportCredentialsException exception
)
```

Sets the `https://developer.android.com/reference/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Intent.html intent` | the result `Intent` to which the exception will be added. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/providerevents/exception/ImportCredentialsException exception` | the exception to be returned to the importer. |

### setImportCredentialsResponse

Added in [1.0.0-beta01](https://developer.android.com/jetpack/androidx/releases/credentials-providerevents#1.0.0-beta01)

```
public static final void setImportCredentialsResponse(
    @NonNull Context context,
    @NonNull Uri uri,
    @NonNull Intent intent,
    @NonNull ImportCredentialsResponse response
)
```

Writes the successful `https://developer.android.com/reference/androidx/credentials/providerevents/transfer/ImportCredentialsResponse` to the content `Uri` provided by the importing framework. The 'responseJson' of the successful `https://developer.android.com/reference/androidx/credentials/providerevents/transfer/ImportCredentialsResponse` will be written to the content 'Uri' to bypass the binder transaction limit. For any additional parameters of the `https://developer.android.com/reference/androidx/credentials/providerevents/transfer/ImportCredentialsResponse` will be written to the intent that is passed in. This intent and `https://developer.android.com/reference/android/app/Activity.html#RESULT_OK` should be set as the result of the activity that was invoked for credential transfer.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | the context |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/net/Uri.html uri` | the uri that was provided by the importer |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Intent.html intent` | the intent to be set on the result of the `https://developer.android.com/reference/android/app/Activity.html` |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/providerevents/transfer/ImportCredentialsResponse response` | the response to be passed to the importer |