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

*** ** * ** ***


```
public 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 methods |
|---|---|
| `abstract boolean` | `https://developer.android.com/reference/androidx/credentials/CredentialProvider#isAvailableOnDevice()()` Determines whether the provider is available on this device, or not. |
| `abstract void` | `https://developer.android.com/reference/androidx/credentials/CredentialProvider#onClearCredential(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 )` Invoked on a request to clear a credential. |
| `abstract void` | `https://developer.android.com/reference/androidx/credentials/CredentialProvider#onCreateCredential(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 )` Invoked on a request to create a credential. |
| `default void` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 34) https://developer.android.com/reference/androidx/credentials/CredentialProvider#onGetCredential(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 )` Complete on a request to get a credential represented by the `https://developer.android.com/reference/androidx/credentials/CredentialProvider#onGetCredential(android.content.Context,androidx.credentials.PrepareGetCredentialResponse.PendingGetCredentialHandle,android.os.CancellationSignal,java.util.concurrent.Executor,androidx.credentials.CredentialManagerCallback)`. |
| `abstract void` | `https://developer.android.com/reference/androidx/credentials/CredentialProvider#onGetCredential(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 )` Invoked on a request to get a credential. |
| `default void` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 34) https://developer.android.com/reference/androidx/credentials/CredentialProvider#onPrepareCredential(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 )` Invoked on a request to prepare for a get-credential operation |
| `default void` | `https://developer.android.com/reference/androidx/credentials/CredentialProvider#onSignalCredentialState(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 )` Invoked on a request to signal an app user's credential state |

## Public methods

### isAvailableOnDevice

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

```
abstract boolean isAvailableOnDevice()
```

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)

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

Invoked on a request to clear a credential.

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

### onCreateCredential

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

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

Invoked on a request to create a credential.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | the client calling context used to potentially launch any UI needed |
| `@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 |

### onGetCredential

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

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

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | the client calling context used to potentially launch any UI needed |
| `@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 |

### onGetCredential

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

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

Invoked on a request to get a credential.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | the client calling context used to potentially launch any UI needed |
| `@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 |

### onPrepareCredential

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

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

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

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

### onSignalCredentialState

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

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

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/credentials/SignalCredentialStateRequest request` | the request for signaling the app user's 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 |