# CredentialManager

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

*** ** * ** ***


```
public interface CredentialManager
```

<br />

*** ** * ** ***

Manages user authentication flows.

An application can call the CredentialManager apis to launch framework UI flows for a user to register a new credential or to consent to a saved credential from supported credential providers, which can then be used to authenticate to the app.

This class contains its own exception types. They represent unique failures during the Credential Manager flow. As required, they can be extended for unique types containing new and unique versions of the exception - either with new 'exception types' (same credential class, different exceptions), or inner subclasses and their exception types (a subclass credential class and all their exception types).

For example, if there is an UNKNOWN exception type, assuming the base Exception is `https://developer.android.com/reference/androidx/credentials/exceptions/ClearCredentialException`, we can add an 'exception type' class for it as follows:

```
class ClearCredentialUnknownException(
    errorMessage: CharSequence? = null
) : ClearCredentialException(TYPE_CLEAR_CREDENTIAL_UNKNOWN_EXCEPTION, errorMessage) {
 // ...Any required impl here...//
 companion object {
      private const val TYPE_CLEAR_CREDENTIAL_UNKNOWN_EXCEPTION: String =
      "androidx.credentials.TYPE_CLEAR_CREDENTIAL_UNKNOWN_EXCEPTION"
  }
}
```

Furthermore, the base class can be subclassed to a new more specific credential type, which then can further be subclassed into individual exception types. The first is an example of a 'inner credential type exception', and the next is a 'exception type' of this subclass exception.

```
class UniqueCredentialBasedOnClearCredentialException(
    type: String,
    errorMessage: CharSequence? = null
) : ClearCredentialException(type, errorMessage) {
 // ... Any required impl here...//
}
// .... code and logic .... //
class UniqueCredentialBasedOnClearCredentialUnknownException(
    errorMessage: CharSequence? = null
) : ClearCredentialException(TYPE_UNIQUE_CREDENTIAL_BASED_ON_CLEAR_CREDENTIAL_UNKNOWN_EXCEPTION,
errorMessage) {
// ... Any required impl here ... //
 companion object {
      private const val
      TYPE_UNIQUE_CREDENTIAL_BASED_ON_CLEAR_CREDENTIAL_UNKNOWN_EXCEPTION: String =
      "androidx.credentials.TYPE_CLEAR_CREDENTIAL_UNKNOWN_EXCEPTION"
  }
}
```

## Summary

| ### Public methods |
|---|---|
| `default void` | `https://developer.android.com/reference/androidx/credentials/CredentialManager#clearCredentialState(androidx.credentials.ClearCredentialStateRequest)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/ClearCredentialStateRequest request)` Clears the current user credential state from all credential providers. |
| `abstract void` | `https://developer.android.com/reference/androidx/credentials/CredentialManager#clearCredentialStateAsync(androidx.credentials.ClearCredentialStateRequest,android.os.CancellationSignal,java.util.concurrent.Executor,androidx.credentials.CredentialManagerCallback)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/ClearCredentialStateRequest request, https://developer.android.com/reference/android/os/CancellationSignal.html cancellationSignal, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/CredentialManagerCallback<https://developer.android.com/reference/java/lang/Void.html, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/exceptions/ClearCredentialException> callback )` Clears the current user credential state from all credential providers. |
| `default static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/CredentialManager` | `https://developer.android.com/reference/androidx/credentials/CredentialManager#create(android.content.Context)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context)` Creates a `https://developer.android.com/reference/androidx/credentials/CredentialManager` based on the given `https://developer.android.com/reference/androidx/credentials/CredentialManager.Companion#create(android.content.Context)`. |
| `default @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/CreateCredentialResponse` | `https://developer.android.com/reference/androidx/credentials/CredentialManager#createCredential(android.content.Context,androidx.credentials.CreateCredentialRequest)( @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/androidx/credentials/CreateCredentialRequest request )` Registers a user credential that can be used to authenticate the user to the app in the future. |
| `abstract void` | `https://developer.android.com/reference/androidx/credentials/CredentialManager#createCredentialAsync(android.content.Context,androidx.credentials.CreateCredentialRequest,android.os.CancellationSignal,java.util.concurrent.Executor,androidx.credentials.CredentialManagerCallback)( @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/androidx/credentials/CreateCredentialRequest request, https://developer.android.com/reference/android/os/CancellationSignal.html cancellationSignal, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/CredentialManagerCallback<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/CreateCredentialResponse, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/exceptions/CreateCredentialException> callback )` Registers a user credential that can be used to authenticate the user to the app in the future. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/PendingIntent.html` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 34) https://developer.android.com/reference/androidx/credentials/CredentialManager#createSettingsPendingIntent()()` Returns a pending intent that shows a screen that lets a user enable a Credential Manager provider. |
| `default @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/GetCredentialResponse` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 34) https://developer.android.com/reference/androidx/credentials/CredentialManager#getCredential(android.content.Context,androidx.credentials.PrepareGetCredentialResponse.PendingGetCredentialHandle)( @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/androidx/credentials/PrepareGetCredentialResponse.PendingGetCredentialHandle pendingGetCredentialHandle )` Requests a credential from the user. |
| `default @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/GetCredentialResponse` | `https://developer.android.com/reference/androidx/credentials/CredentialManager#getCredential(android.content.Context,androidx.credentials.GetCredentialRequest)( @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/androidx/credentials/GetCredentialRequest request )` Requests a credential from the user. |
| `abstract void` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 34) https://developer.android.com/reference/androidx/credentials/CredentialManager#getCredentialAsync(android.content.Context,androidx.credentials.PrepareGetCredentialResponse.PendingGetCredentialHandle,android.os.CancellationSignal,java.util.concurrent.Executor,androidx.credentials.CredentialManagerCallback)( @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/androidx/credentials/PrepareGetCredentialResponse.PendingGetCredentialHandle pendingGetCredentialHandle, https://developer.android.com/reference/android/os/CancellationSignal.html cancellationSignal, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/CredentialManagerCallback<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/GetCredentialResponse, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/exceptions/GetCredentialException> callback )` Requests a credential from the user. |
| `abstract void` | `https://developer.android.com/reference/androidx/credentials/CredentialManager#getCredentialAsync(android.content.Context,androidx.credentials.GetCredentialRequest,android.os.CancellationSignal,java.util.concurrent.Executor,androidx.credentials.CredentialManagerCallback)( @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/androidx/credentials/GetCredentialRequest request, https://developer.android.com/reference/android/os/CancellationSignal.html cancellationSignal, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/CredentialManagerCallback<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/GetCredentialResponse, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/exceptions/GetCredentialException> callback )` Requests a credential from the user. |
| `default @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/PrepareGetCredentialResponse` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 34) https://developer.android.com/reference/androidx/credentials/CredentialManager#prepareGetCredential(androidx.credentials.GetCredentialRequest)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/GetCredentialRequest request)` Prepares for a get-credential operation. |
| `abstract void` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 34) https://developer.android.com/reference/androidx/credentials/CredentialManager#prepareGetCredentialAsync(androidx.credentials.GetCredentialRequest,android.os.CancellationSignal,java.util.concurrent.Executor,androidx.credentials.CredentialManagerCallback)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/GetCredentialRequest request, https://developer.android.com/reference/android/os/CancellationSignal.html cancellationSignal, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/CredentialManagerCallback<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/PrepareGetCredentialResponse, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/exceptions/GetCredentialException> callback )` Prepares for a get-credential operation. |
| `default @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/SignalCredentialStateResponse` | `https://developer.android.com/reference/androidx/credentials/CredentialManager#signalCredentialState(androidx.credentials.SignalCredentialStateRequest)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/SignalCredentialStateRequest request)` Signals a user's public key credential/credentials state to all credential providers. |
| `default void` | `https://developer.android.com/reference/androidx/credentials/CredentialManager#signalCredentialStateAsync(androidx.credentials.SignalCredentialStateRequest,java.util.concurrent.Executor,androidx.credentials.CredentialManagerCallback)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/SignalCredentialStateRequest request, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/CredentialManagerCallback<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/SignalCredentialStateResponse, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/exceptions/publickeycredential/SignalCredentialStateException> callback )` Signals a user's public key credential/credentials state to all credential providers. |

## Public methods

### clearCredentialState

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

```
default void clearCredentialState(@NonNull ClearCredentialStateRequest request)
```

Clears the current user credential state from all credential providers.

You should invoked this api after your user signs out of your app to notify all credential providers that any stored credential session for the given app should be cleared.

A credential provider may have stored an active credential session and use it to limit sign-in options for future get-credential calls. For example, it may prioritize the active credential over any other available credential. When your user explicitly signs out of your app and in order to get the holistic sign-in options the next time, you should call this API to let the provider clear any stored credential session.

If the API is called with `https://developer.android.com/reference/androidx/credentials/ClearCredentialStateRequest#TYPE_CLEAR_RESTORE_CREDENTIAL()` then any restore credential stored on device will be cleared.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/ClearCredentialStateRequest request` | the request for clearing the app user's credential state |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/credentials/exceptions/ClearCredentialException` | If the request fails |

### clearCredentialStateAsync

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

```
abstract void clearCredentialStateAsync(
    @NonNull ClearCredentialStateRequest request,
    CancellationSignal cancellationSignal,
    @NonNull Executor executor,
    @NonNull CredentialManagerCallback<Void, @NonNull ClearCredentialException> callback
)
```

Clears the current user credential state from all credential providers.

This API uses callbacks instead of Kotlin coroutines.

You should invoked this api after your user signs out of your app to notify all credential providers that any stored credential session for the given app should be cleared.

A credential provider may have stored an active credential session and use it to limit sign-in options for future get-credential calls. For example, it may prioritize the active credential over any other available credential. When your user explicitly signs out of your app and in order to get the holistic sign-in options the next time, you should call this API to let the provider clear any stored credential session.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/ClearCredentialStateRequest request` | the request for clearing the app user's credential state |
| `https://developer.android.com/reference/android/os/CancellationSignal.html cancellationSignal` | an optional signal that allows for cancelling this call |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | the callback will take place on this executor |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/CredentialManagerCallback<https://developer.android.com/reference/java/lang/Void.html, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/exceptions/ClearCredentialException> callback` | the callback invoked when the request succeeds or fails |

### create

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

```
default static final @NonNull CredentialManager create(@NonNull Context context)
```

Creates a `https://developer.android.com/reference/androidx/credentials/CredentialManager` based on the given `https://developer.android.com/reference/androidx/credentials/CredentialManager.Companion#create(android.content.Context)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | the context with which the CredentialManager should be associated |

### createCredential

```
default @NonNull CreateCredentialResponse createCredential(
    @NonNull Context context,
    @NonNull CreateCredentialRequest request
)
```

Registers a user credential that can be used to authenticate the user to the app in the future.

The execution potentially launches framework UI flows for a user to view their registration options, grant consent, etc.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | the context used to launch any UI needed; wrap the activity context with a `https://developer.android.com/reference/android/content/MutableContextWrapper.html` to avoid memory leaks and ensure the UI will be launched within the same task stack |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/CreateCredentialRequest request` | the request for creating the credential |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/credentials/exceptions/CreateCredentialException` | If the request fails |

### createCredentialAsync

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

```
abstract void createCredentialAsync(
    @NonNull Context context,
    @NonNull CreateCredentialRequest request,
    CancellationSignal cancellationSignal,
    @NonNull Executor executor,
    @NonNull CredentialManagerCallback<@NonNull CreateCredentialResponse, @NonNull CreateCredentialException> callback
)
```

Registers a user credential that can be used to authenticate the user to the app in the future.

This API uses callbacks instead of Kotlin coroutines.

The execution potentially launches framework UI flows for a user to view their registration options, grant consent, etc.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | the context used to launch any UI needed; wrap the activity context with a `https://developer.android.com/reference/android/content/MutableContextWrapper.html` to avoid memory leaks and ensure the UI will be launched within the same task stack |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/CreateCredentialRequest request` | the request for creating the credential |
| `https://developer.android.com/reference/android/os/CancellationSignal.html cancellationSignal` | an optional signal that allows for cancelling this call |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | the callback will take place on this executor |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/CredentialManagerCallback<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/CreateCredentialResponse, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/exceptions/CreateCredentialException> callback` | the callback invoked when the request succeeds or fails |

### createSettingsPendingIntent

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

```
@RequiresApi(value = 34)
abstract @NonNull PendingIntent createSettingsPendingIntent()
```

Returns a pending intent that shows a screen that lets a user enable a Credential Manager provider.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/PendingIntent.html` | the pending intent that can be launched |

### getCredential

```
@RequiresApi(value = 34)
default @NonNull GetCredentialResponse getCredential(
    @NonNull Context context,
    @NonNull PrepareGetCredentialResponse.PendingGetCredentialHandle pendingGetCredentialHandle
)
```

Requests a credential from the user.

Different from the other `getCredential(GetCredentialRequest, Activity)` API, this API launches the remaining flows to retrieve an app credential from the user, after the completed prefetch work corresponding to the given `pendingGetCredentialHandle`. Use this API to complete the full credential retrieval operation after you initiated a request through the `https://developer.android.com/reference/androidx/credentials/CredentialManager#prepareGetCredential(androidx.credentials.GetCredentialRequest)` API.

The execution can potentially launch UI flows to collect user consent to using a credential, display a picker when multiple credentials exist, etc.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | the context used to launch any UI needed; wrap the activity context with a `https://developer.android.com/reference/android/content/MutableContextWrapper.html` to avoid memory leaks and ensure the UI will be launched within the same task stack |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/PrepareGetCredentialResponse.PendingGetCredentialHandle pendingGetCredentialHandle` | the handle representing the pending operation to resume |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/credentials/exceptions/GetCredentialException` | If the request fails |

### getCredential

```
default @NonNull GetCredentialResponse getCredential(
    @NonNull Context context,
    @NonNull GetCredentialRequest request
)
```

Requests a credential from the user.

The execution potentially launches framework UI flows for a user to view available credentials, consent to using one of them, etc.

```kotlin
import androidx.credentials.Credential
import androidx.credentials.CredentialManager
import androidx.credentials.GetCredentialRequest
import androidx.credentials.GetPasswordOption
import androidx.credentials.GetPublicKeyCredentialOption
import androidx.credentials.PublicKeyCredential
import androidx.credentials.exceptions.GetCredentialException

val credentialManager = CredentialManager.create(context)

val getPasswordOption = GetPasswordOption()

val getPublicKeyCredentialOption =
    GetPublicKeyCredentialOption(
        requestJson = generateGetPasskeyRequestJsonFromServer(),
        // No need to fill this unless you are a browser and are making an origin-based request
        clientDataHash = null,
    )

val request =
    GetCredentialRequest(
        credentialOptions = listOf(getPasswordOption, getPublicKeyCredentialOption)
    )

// The API call will launch a credential selector UI for the user to pick a login credential.
// It will be canceled if this coroutine scope is canceled. If you want the operation to persist
// through your UI lifecycle (e.g. configuration changes), choose a coroutine scope that is
// broader than your UI lifecycle (e.g. ViewModelScope)
yourCoroutineScope.launch {
    try {
        val response =
            credentialManager.getCredential(
                // Important: use an Activity context to ensure that the system credential
                // selector
                // ui is launched within the same activity stack to avoid undefined UI
                // transition
                // behavior.
                context = activity,
                request = request,
            )
        signInWithCredential(response.credential)
    } catch (e: GetCredentialException) {
        handleGetCredentialFailure(e)
    }
}
```

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | the context used to launch any UI needed; wrap the activity context with a `https://developer.android.com/reference/android/content/MutableContextWrapper.html` to avoid memory leaks and ensure the UI will be launched within the same task stack |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/GetCredentialRequest request` | the request for getting the credential |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/credentials/exceptions/GetCredentialException` | If the request fails |

### getCredentialAsync

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

```
@RequiresApi(value = 34)
abstract void getCredentialAsync(
    @NonNull Context context,
    @NonNull PrepareGetCredentialResponse.PendingGetCredentialHandle pendingGetCredentialHandle,
    CancellationSignal cancellationSignal,
    @NonNull Executor executor,
    @NonNull CredentialManagerCallback<@NonNull GetCredentialResponse, @NonNull GetCredentialException> callback
)
```

Requests a credential from the user.

This API uses callbacks instead of Kotlin coroutines.

Different from the other `getCredentialAsync(GetCredentialRequest, Activity)` API, this API launches the remaining flows to retrieve an app credential from the user, after the completed prefetch work corresponding to the given `pendingGetCredentialHandle`. Use this API to complete the full credential retrieval operation after you initiated a request through the `https://developer.android.com/reference/androidx/credentials/CredentialManager#prepareGetCredentialAsync(androidx.credentials.GetCredentialRequest,android.os.CancellationSignal,java.util.concurrent.Executor,androidx.credentials.CredentialManagerCallback)` API.

The execution can potentially launch UI flows to collect user consent to using a credential, display a picker when multiple credentials exist, etc.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | the context used to launch any UI needed; wrap the activity context with a `https://developer.android.com/reference/android/content/MutableContextWrapper.html` to avoid memory leaks and ensure the UI will be launched within the same task stack |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/PrepareGetCredentialResponse.PendingGetCredentialHandle pendingGetCredentialHandle` | the handle representing the pending operation to resume |
| `https://developer.android.com/reference/android/os/CancellationSignal.html cancellationSignal` | an optional signal that allows for cancelling this call |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | the callback will take place on this executor |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/CredentialManagerCallback<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/GetCredentialResponse, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/exceptions/GetCredentialException> callback` | the callback invoked when the request succeeds or fails |

### getCredentialAsync

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

```
abstract void getCredentialAsync(
    @NonNull Context context,
    @NonNull GetCredentialRequest request,
    CancellationSignal cancellationSignal,
    @NonNull Executor executor,
    @NonNull CredentialManagerCallback<@NonNull GetCredentialResponse, @NonNull GetCredentialException> callback
)
```

Requests a credential from the user.

This API uses callbacks instead of Kotlin coroutines.

The execution potentially launches framework UI flows for a user to view available credentials, consent to using one of them, etc.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | the context used to launch any UI needed; wrap the activity context with a `https://developer.android.com/reference/android/content/MutableContextWrapper.html` to avoid memory leaks and ensure the UI will be launched within the same task stack |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/GetCredentialRequest request` | the request for getting the credential |
| `https://developer.android.com/reference/android/os/CancellationSignal.html cancellationSignal` | an optional signal that allows for cancelling this call |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | the callback will take place on this executor |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/CredentialManagerCallback<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/GetCredentialResponse, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/exceptions/GetCredentialException> callback` | the callback invoked when the request succeeds or fails |

### prepareGetCredential

```
@RequiresApi(value = 34)
default @NonNull PrepareGetCredentialResponse prepareGetCredential(@NonNull GetCredentialRequest request)
```

Prepares for a get-credential operation. Returns a `https://developer.android.com/reference/androidx/credentials/PrepareGetCredentialResponse` that can later be used to launch the credential retrieval UI flow to finalize a user credential for your app.

This API doesn't invoke any UI. It only performs the preparation work so that you can later launch the remaining get-credential operation (involves UIs) through the `https://developer.android.com/reference/androidx/credentials/CredentialManager#getCredential(android.content.Context,androidx.credentials.GetCredentialRequest)` API which incurs less latency than executing the whole operation in one call.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/GetCredentialRequest request` | the request for getting the credential |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/credentials/exceptions/GetCredentialException` | If the request fails |

### prepareGetCredentialAsync

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

```
@RequiresApi(value = 34)
abstract void prepareGetCredentialAsync(
    @NonNull GetCredentialRequest request,
    CancellationSignal cancellationSignal,
    @NonNull Executor executor,
    @NonNull CredentialManagerCallback<@NonNull PrepareGetCredentialResponse, @NonNull GetCredentialException> callback
)
```

Prepares for a get-credential operation. Returns a `https://developer.android.com/reference/androidx/credentials/PrepareGetCredentialResponse` that can later be used to launch the credential retrieval UI flow to finalize a user credential for your app.

This API uses callbacks instead of Kotlin coroutines.

This API doesn't invoke any UI. It only performs the preparation work so that you can later launch the remaining get-credential operation (involves UIs) through the `https://developer.android.com/reference/androidx/credentials/CredentialManager#getCredentialAsync(android.content.Context,androidx.credentials.GetCredentialRequest,android.os.CancellationSignal,java.util.concurrent.Executor,androidx.credentials.CredentialManagerCallback)` API which incurs less latency than executing the whole operation in one call.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/GetCredentialRequest request` | the request for getting the credential |
| `https://developer.android.com/reference/android/os/CancellationSignal.html cancellationSignal` | an optional signal that allows for cancelling this call |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | the callback will take place on this executor |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/CredentialManagerCallback<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/PrepareGetCredentialResponse, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/exceptions/GetCredentialException> callback` | the callback invoked when the request succeeds or fails |

### signalCredentialState

```
default @NonNull SignalCredentialStateResponse signalCredentialState(@NonNull SignalCredentialStateRequest request)
```

Signals a user's public key credential/credentials state to all credential providers.

The execution does not invoke any UI but simply informs credential providers about the state of a user's credential. Supported signal types are `https://developer.android.com/reference/androidx/credentials/SignalAllAcceptedCredentialIdsRequest`, `https://developer.android.com/reference/androidx/credentials/SignalCurrentUserDetailsRequest`, `https://developer.android.com/reference/androidx/credentials/SignalUnknownCredentialRequest`.

A successful response does not indicate that any provider honored the signal request; it however indicates that the request was well-formed, passes all necessary checks, and has been passed along to all enabled providers, if any.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/SignalCredentialStateRequest request` | the request for signaling the credential state |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/credentials/exceptions/publickeycredential/SignalCredentialStateException` | If the request parsing fails |

### signalCredentialStateAsync

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

```
default void signalCredentialStateAsync(
    @NonNull SignalCredentialStateRequest request,
    @NonNull Executor executor,
    @NonNull CredentialManagerCallback<@NonNull SignalCredentialStateResponse, @NonNull SignalCredentialStateException> callback
)
```

Signals a user's public key credential/credentials state to all credential providers.

This API uses callbacks instead of Kotlin coroutines.

The execution does not invoke any UI but simply informs credential providers about the state of a user's credential. Supported signal types are `https://developer.android.com/reference/androidx/credentials/SignalAllAcceptedCredentialIdsRequest`, `https://developer.android.com/reference/androidx/credentials/SignalCurrentUserDetailsRequest`, `https://developer.android.com/reference/androidx/credentials/SignalUnknownCredentialRequest`.

A successful response does not indicate that any provider honored the signal request; it however indicates that the request was well-formed, passes all necessary checks, and has been passed along to all enabled providers, if any.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/SignalCredentialStateRequest request` | the request for signaling the credential state |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | the callback will take place on this executor |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/CredentialManagerCallback<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/SignalCredentialStateResponse, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/exceptions/publickeycredential/SignalCredentialStateException> callback` | the callback invoked when the request succeeds or fails |