# CredentialProvider

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

*** ** * ** ***


```
interface CredentialProvider
```

<br />

*** ** * ** ***

Provider interface to be implemented by system credential providers that will fulfill Credential Manager requests. The implementation **must** have a constructor that takes in a context.

Note that for SDK version 33 and below, this interface can be implemented by any OEM provider
that wishes to return credentials. The implementation must have a constructor with a context
parameter. A provider must :

1. Release a dedicated provider library that developers can add as a dependency.
2. Include an empty CredentialProviderService in the provider library for the purposes of exposing a meta-data tag in the Android Manifest file.
3. Add the name of the class that is implementing this interface, as a value to the meta-data tag described above.
4. Make sure that there is only one provider implementation on the device. If the device already has a provider installed, and the developer specifies more than one provider dependencies, credential manager will error out.

For SDK version 34 and above, this interface will only be implemented by an internal class
that will route all requests to the android framework. Providers will need to register directly
with the framework to provide credentials.

## Summary

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialProvider#isAvailableOnDevice()()` Determines whether the provider is available on this device, or not. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialProvider#onClearCredential(androidx.credentials.ClearCredentialStateRequest,android.os.CancellationSignal,java.util.concurrent.Executor,androidx.credentials.CredentialManagerCallback)( request: https://developer.android.com/reference/kotlin/androidx/credentials/ClearCredentialStateRequest, cancellationSignal: https://developer.android.com/reference/android/os/CancellationSignal.html?, executor: https://developer.android.com/reference/java/util/concurrent/Executor.html, callback: https://developer.android.com/reference/kotlin/androidx/credentials/CredentialManagerCallback<https://developer.android.com/reference/java/lang/Void.html?, https://developer.android.com/reference/kotlin/androidx/credentials/exceptions/ClearCredentialException> )` Invoked on a request to clear a credential. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialProvider#onCreateCredential(android.content.Context,androidx.credentials.CreateCredentialRequest,android.os.CancellationSignal,java.util.concurrent.Executor,androidx.credentials.CredentialManagerCallback)( context: https://developer.android.com/reference/android/content/Context.html, request: https://developer.android.com/reference/kotlin/androidx/credentials/CreateCredentialRequest, cancellationSignal: https://developer.android.com/reference/android/os/CancellationSignal.html?, executor: https://developer.android.com/reference/java/util/concurrent/Executor.html, callback: https://developer.android.com/reference/kotlin/androidx/credentials/CredentialManagerCallback<https://developer.android.com/reference/kotlin/androidx/credentials/CreateCredentialResponse, https://developer.android.com/reference/kotlin/androidx/credentials/exceptions/CreateCredentialException> )` Invoked on a request to create a credential. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 34) https://developer.android.com/reference/kotlin/androidx/credentials/CredentialProvider#onGetCredential(android.content.Context,androidx.credentials.PrepareGetCredentialResponse.PendingGetCredentialHandle,android.os.CancellationSignal,java.util.concurrent.Executor,androidx.credentials.CredentialManagerCallback)( context: https://developer.android.com/reference/android/content/Context.html, pendingGetCredentialHandle: https://developer.android.com/reference/kotlin/androidx/credentials/PrepareGetCredentialResponse.PendingGetCredentialHandle, cancellationSignal: https://developer.android.com/reference/android/os/CancellationSignal.html?, executor: https://developer.android.com/reference/java/util/concurrent/Executor.html, callback: https://developer.android.com/reference/kotlin/androidx/credentials/CredentialManagerCallback<https://developer.android.com/reference/kotlin/androidx/credentials/GetCredentialResponse, https://developer.android.com/reference/kotlin/androidx/credentials/exceptions/GetCredentialException> )` Complete on a request to get a credential represented by the `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialProvider#onGetCredential(android.content.Context,androidx.credentials.PrepareGetCredentialResponse.PendingGetCredentialHandle,android.os.CancellationSignal,java.util.concurrent.Executor,androidx.credentials.CredentialManagerCallback)`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialProvider#onGetCredential(android.content.Context,androidx.credentials.GetCredentialRequest,android.os.CancellationSignal,java.util.concurrent.Executor,androidx.credentials.CredentialManagerCallback)( context: https://developer.android.com/reference/android/content/Context.html, request: https://developer.android.com/reference/kotlin/androidx/credentials/GetCredentialRequest, cancellationSignal: https://developer.android.com/reference/android/os/CancellationSignal.html?, executor: https://developer.android.com/reference/java/util/concurrent/Executor.html, callback: https://developer.android.com/reference/kotlin/androidx/credentials/CredentialManagerCallback<https://developer.android.com/reference/kotlin/androidx/credentials/GetCredentialResponse, https://developer.android.com/reference/kotlin/androidx/credentials/exceptions/GetCredentialException> )` Invoked on a request to get a credential. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 34) https://developer.android.com/reference/kotlin/androidx/credentials/CredentialProvider#onPrepareCredential(androidx.credentials.GetCredentialRequest,android.os.CancellationSignal,java.util.concurrent.Executor,androidx.credentials.CredentialManagerCallback)( request: https://developer.android.com/reference/kotlin/androidx/credentials/GetCredentialRequest, cancellationSignal: https://developer.android.com/reference/android/os/CancellationSignal.html?, executor: https://developer.android.com/reference/java/util/concurrent/Executor.html, callback: https://developer.android.com/reference/kotlin/androidx/credentials/CredentialManagerCallback<https://developer.android.com/reference/kotlin/androidx/credentials/PrepareGetCredentialResponse, https://developer.android.com/reference/kotlin/androidx/credentials/exceptions/GetCredentialException> )` Invoked on a request to prepare for a get-credential operation |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialProvider#onSignalCredentialState(androidx.credentials.SignalCredentialStateRequest,java.util.concurrent.Executor,androidx.credentials.CredentialManagerCallback)( request: https://developer.android.com/reference/kotlin/androidx/credentials/SignalCredentialStateRequest, executor: https://developer.android.com/reference/java/util/concurrent/Executor.html, callback: https://developer.android.com/reference/kotlin/androidx/credentials/CredentialManagerCallback<https://developer.android.com/reference/kotlin/androidx/credentials/SignalCredentialStateResponse, https://developer.android.com/reference/kotlin/androidx/credentials/exceptions/publickeycredential/SignalCredentialStateException> )` Invoked on a request to signal an app user's credential state |

## Public functions

### isAvailableOnDevice

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

```
fun isAvailableOnDevice(): Boolean
```

Determines whether the provider is available on this device, or not.

### onClearCredential

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

```
fun onClearCredential(
    request: ClearCredentialStateRequest,
    cancellationSignal: CancellationSignal?,
    executor: Executor,
    callback: CredentialManagerCallback<Void?, ClearCredentialException>
): Unit
```

Invoked on a request to clear a credential.

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

### onCreateCredential

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

```
fun onCreateCredential(
    context: Context,
    request: CreateCredentialRequest,
    cancellationSignal: CancellationSignal?,
    executor: Executor,
    callback: CredentialManagerCallback<CreateCredentialResponse, CreateCredentialException>
): Unit
```

Invoked on a request to create a credential.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | the client calling context used to potentially launch any UI needed |
| `request: https://developer.android.com/reference/kotlin/androidx/credentials/CreateCredentialRequest` | the request for creating the credential |
| `cancellationSignal: https://developer.android.com/reference/android/os/CancellationSignal.html?` | an optional signal that allows for cancelling this call |
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html` | the callback will take place on this executor |
| `callback: https://developer.android.com/reference/kotlin/androidx/credentials/CredentialManagerCallback<https://developer.android.com/reference/kotlin/androidx/credentials/CreateCredentialResponse, https://developer.android.com/reference/kotlin/androidx/credentials/exceptions/CreateCredentialException>` | the callback invoked when the request succeeds or fails |

### onGetCredential

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

```
@RequiresApi(value = 34)
open fun onGetCredential(
    context: Context,
    pendingGetCredentialHandle: PrepareGetCredentialResponse.PendingGetCredentialHandle,
    cancellationSignal: CancellationSignal?,
    executor: Executor,
    callback: CredentialManagerCallback<GetCredentialResponse, GetCredentialException>
): Unit
```

Complete on a request to get a credential represented by the `https://developer.android.com/reference/kotlin/androidx/credentials/CredentialProvider#onGetCredential(android.content.Context,androidx.credentials.PrepareGetCredentialResponse.PendingGetCredentialHandle,android.os.CancellationSignal,java.util.concurrent.Executor,androidx.credentials.CredentialManagerCallback)`.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | the client calling context used to potentially launch any UI needed |
| `pendingGetCredentialHandle: https://developer.android.com/reference/kotlin/androidx/credentials/PrepareGetCredentialResponse.PendingGetCredentialHandle` | the handle representing the pending operation to resume |
| `cancellationSignal: https://developer.android.com/reference/android/os/CancellationSignal.html?` | an optional signal that allows for cancelling this call |
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html` | the callback will take place on this executor |
| `callback: https://developer.android.com/reference/kotlin/androidx/credentials/CredentialManagerCallback<https://developer.android.com/reference/kotlin/androidx/credentials/GetCredentialResponse, https://developer.android.com/reference/kotlin/androidx/credentials/exceptions/GetCredentialException>` | the callback invoked when the request succeeds or fails |

### onGetCredential

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

```
fun onGetCredential(
    context: Context,
    request: GetCredentialRequest,
    cancellationSignal: CancellationSignal?,
    executor: Executor,
    callback: CredentialManagerCallback<GetCredentialResponse, GetCredentialException>
): Unit
```

Invoked on a request to get a credential.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | the client calling context used to potentially launch any UI needed |
| `request: https://developer.android.com/reference/kotlin/androidx/credentials/GetCredentialRequest` | the request for getting the credential |
| `cancellationSignal: https://developer.android.com/reference/android/os/CancellationSignal.html?` | an optional signal that allows for cancelling this call |
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html` | the callback will take place on this executor |
| `callback: https://developer.android.com/reference/kotlin/androidx/credentials/CredentialManagerCallback<https://developer.android.com/reference/kotlin/androidx/credentials/GetCredentialResponse, https://developer.android.com/reference/kotlin/androidx/credentials/exceptions/GetCredentialException>` | the callback invoked when the request succeeds or fails |

### onPrepareCredential

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

```
@RequiresApi(value = 34)
open fun onPrepareCredential(
    request: GetCredentialRequest,
    cancellationSignal: CancellationSignal?,
    executor: Executor,
    callback: CredentialManagerCallback<PrepareGetCredentialResponse, GetCredentialException>
): Unit
```

Invoked on a request to prepare for a get-credential operation

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

### onSignalCredentialState

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

```
open fun onSignalCredentialState(
    request: SignalCredentialStateRequest,
    executor: Executor,
    callback: CredentialManagerCallback<SignalCredentialStateResponse, SignalCredentialStateException>
): Unit
```

Invoked on a request to signal an app user's credential state

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