Provide sign-in hints to a user

Requests to retrieve user credentials can fail when a user has not yet saved
credentials or when a user has not yet signed up to your app. In these
situations, use the Credentials API to retrieve sign-in hints, such as the
user's name and email address. Use these hints to pre-fill your app's sign-in
and sign-up forms, speeding up your app's on-boarding process.

On Android 6.0 (Marshmallow) and newer, your app does not need to request
any device or runtime permissions to retrieve sign-in hints with the
Credentials API.

Before you begin

Retrieve sign-in hints

To retrieve the sign-in hints, first configure the hint selector dialog by
creating a HintRequest
object. Then, pass the HintRequest object to
CredentialsClient.getHintPickerIntent()
to get an intent to prompt the user to choose an email address. Finally, start the
intent with startIntentSenderForResult().

Then, in the activity's onActivityResult() method, retrieve the hints from the
Credential.EXTRA_KEY parcel, check whether the user is in your user database,
and start the appropriate activity with the credentials hint.

Pre-fill the sign-in form

If the user is in your user database and you started your app's sign-in
activity, you can (optionally) check if the Credential object contains an ID
token. If so, you can sign in the user with the ID token,
without requiring the user to type a password.

If the Credential object doesn't contain an ID token (or you don't want to use
the ID token), pre-fill the sign-in fields with the hints that you added to the
intent.

Optionally, you can also check if the Credential object contains an
ID token that has a
verified email address. If so, you can skip your app's email verification step,
since the email address has already been verified by Google.