# 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)

*** ** * ** ***


```
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/kotlin/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/kotlin/androidx/credentials/providerevents/ProviderEventsManager#registerExport(androidx.credentials.providerevents.transfer.RegisterExportRequest)`.

When user selects one of the `https://developer.android.com/reference/kotlin/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 companion functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/credentials/providerevents/transfer/ProviderImportCredentialsRequest?` | `https://developer.android.com/reference/kotlin/androidx/credentials/providerevents/IntentHandler#retrieveProviderImportCredentialsRequest(android.content.Intent)(intent: https://developer.android.com/reference/android/content/Intent.html)` Extracts the `https://developer.android.com/reference/kotlin/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`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/credentials/providerevents/IntentHandler#setImportCredentialsException(android.content.Intent,androidx.credentials.providerevents.exception.ImportCredentialsException)( intent: https://developer.android.com/reference/android/content/Intent.html, exception: https://developer.android.com/reference/kotlin/androidx/credentials/providerevents/exception/ImportCredentialsException )` Sets the `https://developer.android.com/reference/kotlin/androidx/credentials/providerevents/exception/ImportCredentialsException` if an error is encountered when the provider application is invoked to fulfill the credential import request. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/credentials/providerevents/IntentHandler#setImportCredentialsResponse(android.content.Context,android.net.Uri,android.content.Intent,androidx.credentials.providerevents.transfer.ImportCredentialsResponse)( context: https://developer.android.com/reference/android/content/Context.html, uri: https://developer.android.com/reference/android/net/Uri.html, intent: https://developer.android.com/reference/android/content/Intent.html, response: https://developer.android.com/reference/kotlin/androidx/credentials/providerevents/transfer/ImportCredentialsResponse )` Writes the successful `https://developer.android.com/reference/kotlin/androidx/credentials/providerevents/transfer/ImportCredentialsResponse` to the content `Uri` provided by the importing framework. |

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

## Public companion functions

### retrieveProviderImportCredentialsRequest

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

```
fun retrieveProviderImportCredentialsRequest(intent: Intent): ProviderImportCredentialsRequest?
```

Extracts the `https://developer.android.com/reference/kotlin/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 |
|---|---|
| `intent: https://developer.android.com/reference/android/content/Intent.html` | the `Intent` received by the provider's exporting `Activity`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/credentials/providerevents/transfer/ProviderImportCredentialsRequest?` | the parsed `https://developer.android.com/reference/kotlin/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)

```
fun setImportCredentialsException(
    intent: Intent,
    exception: ImportCredentialsException
): Unit
```

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

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

Writes the successful `https://developer.android.com/reference/kotlin/androidx/credentials/providerevents/transfer/ImportCredentialsResponse` to the content `Uri` provided by the importing framework. The 'responseJson' of the successful `https://developer.android.com/reference/kotlin/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/kotlin/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 |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | the context |
| `uri: https://developer.android.com/reference/android/net/Uri.html` | the uri that was provided by the importer |
| `intent: https://developer.android.com/reference/android/content/Intent.html` | the intent to be set on the result of the `https://developer.android.com/reference/android/app/Activity.html` |
| `response: https://developer.android.com/reference/kotlin/androidx/credentials/providerevents/transfer/ImportCredentialsResponse` | the response to be passed to the importer |

## Public constructors

### IntentHandler

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

```
IntentHandler()
```