Stay organized with collections Save and categorize content based on your preferences.

CredentialManager

public final class CredentialManager
extends Object

java.lang.Object
   ↳ android.credentials.CredentialManager


Manages user authentication flows.

Note that an application should call the Jetpack CredentialManager apis instead of directly calling these framework apis.

The CredentialManager apis 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.

Summary

Public methods

void clearCredentialState(ClearCredentialStateRequest request, CancellationSignal cancellationSignal, Executor executor, OutcomeReceiver<VoidClearCredentialStateException> callback)

Clears the current user credential state from all credential providers.

void createCredential(CreateCredentialRequest request, Activity activity, CancellationSignal cancellationSignal, Executor executor, OutcomeReceiver<CreateCredentialResponseCreateCredentialException> callback)

Launches the necessary flows to register an app credential for the user.

void getCredential(GetCredentialRequest request, Activity activity, CancellationSignal cancellationSignal, Executor executor, OutcomeReceiver<GetCredentialResponseGetCredentialException> callback)

Launches the necessary flows to retrieve an app credential from the user.

boolean isEnabledCredentialProviderService(ComponentName componentName)

Returns true if the calling application provides a CredentialProviderService that is enabled for the current user, or false otherwise.

Inherited methods

Public methods

clearCredentialState

public void clearCredentialState (ClearCredentialStateRequest request, 
                CancellationSignal cancellationSignal, 
                Executor executor, 
                OutcomeReceiver<VoidClearCredentialStateException> callback)

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.

Parameters
request ClearCredentialStateRequest: the request data This value cannot be null.

cancellationSignal CancellationSignal: an optional signal that allows for cancelling this call This value may be null.

executor Executor: the callback will take place on this Executor Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread. This value cannot be null.

callback OutcomeReceiver: the callback invoked when the request succeeds or fails This value cannot be null.

createCredential

public void createCredential (CreateCredentialRequest request, 
                Activity activity, 
                CancellationSignal cancellationSignal, 
                Executor executor, 
                OutcomeReceiver<CreateCredentialResponseCreateCredentialException> callback)

Launches the necessary flows to register an app credential for the user.

The execution can potentially launch UI flows to collect user consent to creating or storing the new credential, etc. Callers (e.g. browsers) may optionally set origin in CreateCredentialRequest for an app different from their own, to be able to get credentials on behalf of that app. They would need additional permission ERROR(/CREDENTIAL_MANAGER_SET_ORIGIN) to use this functionality

Parameters
request CreateCredentialRequest: the request specifying type(s) of credentials to get from the user This value cannot be null.

activity Activity: the activity used to launch any UI needed This value cannot be null.

cancellationSignal CancellationSignal: an optional signal that allows for cancelling this call This value may be null.

executor Executor: the callback will take place on this Executor Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread. This value cannot be null.

callback OutcomeReceiver: the callback invoked when the request succeeds or fails This value cannot be null.

getCredential

public void getCredential (GetCredentialRequest request, 
                Activity activity, 
                CancellationSignal cancellationSignal, 
                Executor executor, 
                OutcomeReceiver<GetCredentialResponseGetCredentialException> callback)

Launches the necessary flows to retrieve an app credential from the user.

The execution can potentially launch UI flows to collect user consent to using a credential, display a picker when multiple credentials exist, etc. Callers (e.g. browsers) may optionally set origin in GetCredentialRequest for an app different from their own, to be able to get credentials on behalf of that app. They would need additional permission ERROR(/CREDENTIAL_MANAGER_SET_ORIGIN) to use this functionality

Parameters
request GetCredentialRequest: the request specifying type(s) of credentials to get from the user This value cannot be null.

activity Activity: the activity used to launch any UI needed This value cannot be null.

cancellationSignal CancellationSignal: an optional signal that allows for cancelling this call This value may be null.

executor Executor: the callback will take place on this Executor Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread. This value cannot be null.

callback OutcomeReceiver: the callback invoked when the request succeeds or fails This value cannot be null.

isEnabledCredentialProviderService

public boolean isEnabledCredentialProviderService (ComponentName componentName)

Returns true if the calling application provides a CredentialProviderService that is enabled for the current user, or false otherwise. CredentialProviderServices are enabled on a per-service basis so the individual component name of the service should be passed in here.

Parameters
componentName ComponentName: the component name to check is enabled This value cannot be null.

Returns
boolean