# GetCredentialRequest

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

*** ** * ** ***

<br />

```
public final class GetCredentialRequest
```

<br />

*** ** * ** ***

Encapsulates a request to get a user credential.

An application can construct such a request by adding one or more types of `https://developer.android.com/reference/androidx/credentials/CredentialOption`, and then call `https://developer.android.com/reference/androidx/credentials/CredentialManager#getCredential(android.content.Context,androidx.credentials.GetCredentialRequest)` to launch framework UI flows to allow the user to consent to using a previously saved credential for the given application.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | If `https://developer.android.com/reference/androidx/credentials/GetCredentialRequest#credentialOptions()` is empty or contains `https://developer.android.com/reference/androidx/credentials/GetRestoreCredentialOption` with another option (i.e. `https://developer.android.com/reference/androidx/credentials/GetPasswordOption` or `https://developer.android.com/reference/androidx/credentials/GetPublicKeyCredentialOption`). |

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/credentials/GetCredentialRequest.Builder` A builder for `https://developer.android.com/reference/androidx/credentials/GetCredentialRequest`. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/credentials/GetCredentialRequest#GetCredentialRequest(kotlin.collections.List,kotlin.String,kotlin.Boolean,android.content.ComponentName,kotlin.Boolean)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/CredentialOption> credentialOptions, https://developer.android.com/reference/java/lang/String.html origin, boolean preferIdentityDocUi, https://developer.android.com/reference/android/content/ComponentName.html preferUiBrandingComponentName, boolean preferImmediatelyAvailableCredentials )` |

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/GetCredentialRequest` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 34) https://developer.android.com/reference/androidx/credentials/GetCredentialRequest#createFrom(android.credentials.GetCredentialRequest)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/credentials/GetCredentialRequest.html request)` Parses the `https://developer.android.com/reference/androidx/credentials/GetCredentialRequest.Companion#createFrom(android.credentials.GetCredentialRequest)` into an instance of `https://developer.android.com/reference/androidx/credentials/GetCredentialRequest`. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/GetCredentialRequest` | `https://developer.android.com/reference/androidx/credentials/GetCredentialRequest#createFrom(kotlin.collections.List,kotlin.String,android.os.Bundle)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/CredentialOption> credentialOptions, https://developer.android.com/reference/java/lang/String.html origin, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/os/Bundle.html metadata )` Parses the raw data into an instance of `https://developer.android.com/reference/androidx/credentials/GetCredentialRequest`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/CredentialOption>` | `https://developer.android.com/reference/androidx/credentials/GetCredentialRequest#getCredentialOptions()()` the list of `https://developer.android.com/reference/androidx/credentials/CredentialOption` from which the user can choose one to authenticate to the app |
| `final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/credentials/GetCredentialRequest#getOrigin()()` the origin of a different application if the request is being made on behalf of that application. |
| `final boolean` | `https://developer.android.com/reference/androidx/credentials/GetCredentialRequest#getPreferIdentityDocUi()()` the value which signals if the UI should be tailored to display an identity document like driver license etc. |
| `final https://developer.android.com/reference/android/content/ComponentName.html` | `https://developer.android.com/reference/androidx/credentials/GetCredentialRequest#getPreferUiBrandingComponentName()()` a service `https://developer.android.com/reference/android/content/ComponentName.html` from which the Credential Selector UI will pull its label and icon to render top level branding. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/os/Bundle.html` | `https://developer.android.com/reference/androidx/credentials/GetCredentialRequest#getRequestMetadataBundle(androidx.credentials.GetCredentialRequest)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/GetCredentialRequest request)` Returns the request metadata as a `Bundle`. |
| `final boolean` | `https://developer.android.com/reference/androidx/credentials/GetCredentialRequest#preferImmediatelyAvailableCredentials()()` true if you prefer the operation to return immediately when there is no available credentials instead of falling back to discovering remote options, and false (default) otherwise |

## Public constructors

### GetCredentialRequest

```
public GetCredentialRequest(
    @NonNull List<@NonNull CredentialOption> credentialOptions,
    String origin,
    boolean preferIdentityDocUi,
    ComponentName preferUiBrandingComponentName,
    boolean preferImmediatelyAvailableCredentials
)
```

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/CredentialOption> credentialOptions` | the list of `https://developer.android.com/reference/androidx/credentials/CredentialOption` from which the user can choose one to authenticate to the app |
| `https://developer.android.com/reference/java/lang/String.html origin` | the origin of a different application if the request is being made on behalf of that application (Note: for API level \>=34, setting a non-null value for this parameter, will throw a SecurityException if android.permission.CREDENTIAL_MANAGER_SET_ORIGIN is not present) |
| `boolean preferIdentityDocUi` | the value which signals if the UI should be tailored to display an identity document like driver license etc |
| `https://developer.android.com/reference/android/content/ComponentName.html preferUiBrandingComponentName` | a service `https://developer.android.com/reference/android/content/ComponentName.html` from which the Credential Selector UI will pull its label and icon to render top level branding (Note: your app must have the permission android.permission.CREDENTIAL_MANAGER_SET_ALLOWED_PROVIDERS to specify this, or it would not take effect; also this bit may not take effect for Android API level 33 and below, depending on the pre-34 provider(s) you have chosen |
| `boolean preferImmediatelyAvailableCredentials` | true if you prefer the operation to return immediately when there is no available credentials instead of falling back to discovering remote options, and false (default) otherwise |

## Public methods

### createFrom

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/credentials#1.5.0)

```
@RequiresApi(value = 34)
public static final @NonNull GetCredentialRequest createFrom(@NonNull GetCredentialRequest request)
```

Parses the `https://developer.android.com/reference/androidx/credentials/GetCredentialRequest.Companion#createFrom(android.credentials.GetCredentialRequest)` into an instance of `https://developer.android.com/reference/androidx/credentials/GetCredentialRequest`.

It is recommended to construct a GetCredentialRequest by direct constructor calls, instead of using this API. This API should only be used by a small subset of system apps that reconstruct an existing object for user interactions such as collecting consents.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/credentials/GetCredentialRequest.html request` | the framework GetCredentialRequest object |

### createFrom

```
public static final @NonNull GetCredentialRequest createFrom(
    @NonNull List<@NonNull CredentialOption> credentialOptions,
    String origin,
    @NonNull Bundle metadata
)
```

Parses the raw data into an instance of `https://developer.android.com/reference/androidx/credentials/GetCredentialRequest`.

It is recommended to construct a GetCredentialRequest by direct constructor calls, instead of using this API. This API should only be used by a small subset of system apps that reconstruct an existing object for user interactions such as collecting consents.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/CredentialOption> credentialOptions` | matches `https://developer.android.com/reference/androidx/credentials/GetCredentialRequest#credentialOptions()` |
| `https://developer.android.com/reference/java/lang/String.html origin` | matches `https://developer.android.com/reference/androidx/credentials/GetCredentialRequest#origin()` |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/os/Bundle.html metadata` | request metadata serialized as a Bundle using `https://developer.android.com/reference/androidx/credentials/GetCredentialRequest#getRequestMetadataBundle(androidx.credentials.GetCredentialRequest)` |

### getCredentialOptions

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/credentials#1.2.0)

```
public final @NonNull List<@NonNull CredentialOption> getCredentialOptions()
```

the list of `https://developer.android.com/reference/androidx/credentials/CredentialOption` from which the user can choose one to authenticate to the app

### getOrigin

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/credentials#1.2.0)

```
public final String getOrigin()
```

the origin of a different application if the request is being made on behalf of that application. For API level \>=34, setting a non-null value for this parameter, will throw a SecurityException if android.permission.CREDENTIAL_MANAGER_SET_ORIGIN is not present.

### getPreferIdentityDocUi

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/credentials#1.2.0)

```
public final boolean getPreferIdentityDocUi()
```

the value which signals if the UI should be tailored to display an identity document like driver license etc.

### getPreferUiBrandingComponentName

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/credentials#1.2.0)

```
public final ComponentName getPreferUiBrandingComponentName()
```

a service `https://developer.android.com/reference/android/content/ComponentName.html` from which the Credential Selector UI will pull its label and icon to render top level branding. Your app must have the permission android.permission.CREDENTIAL_MANAGER_SET_ALLOWED_PROVIDERS to specify this, or it would not take effect. Notice that this bit may not take effect for Android API level 33 and below, depending on the pre-34 provider(s) you have chosen.

### getRequestMetadataBundle

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/credentials#1.5.0)

```
public static final @NonNull Bundle getRequestMetadataBundle(@NonNull GetCredentialRequest request)
```

Returns the request metadata as a `Bundle`.

This API should only be used by OEM services and library groups.

Note: this is not the equivalent of the complete request itself. For example, it does not include the request's `credentialOptions` or `origin`.

### preferImmediatelyAvailableCredentials

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/credentials#1.5.0)

```
public final boolean preferImmediatelyAvailableCredentials()
```

true if you prefer the operation to return immediately when there is no available credentials instead of falling back to discovering remote options, and false (default) otherwise