[null,null,["最后更新时间 (UTC):2025-07-25。"],[[["\u003cp\u003eSmart Lock for Passwords is deprecated; migrate to Credential Manager for enhanced security and user experience with passkeys, passwords, and federated identities.\u003c/p\u003e\n"],["\u003cp\u003eUse the Credentials API to retrieve sign-in hints (like name and email) to pre-fill forms, streamlining user onboarding, especially when credentials are not yet saved.\u003c/p\u003e\n"],["\u003cp\u003eAndroid 6.0 (Marshmallow) and newer do not require any special permissions to retrieve sign-in hints with the Credentials API.\u003c/p\u003e\n"],["\u003cp\u003eRetrieve sign-in hints by configuring a HintRequest, launching a picker intent, and handling the result in \u003ccode\u003eonActivityResult()\u003c/code\u003e to pre-fill sign-in or sign-up forms based on user status.\u003c/p\u003e\n"],["\u003cp\u003eConsider using ID tokens for automatic sign-in or bypassing email verification if available within the retrieved Credential object.\u003c/p\u003e\n"]]],[],null,["# Provide sign-in hints to a user\n\n| **Deprecated:** Smart Lock for Passwords is deprecated. To ensure the continued security and usability of your app, [migrate to\n| Credential Manager](https://developer.android.com/training/sign-in/passkeys/) today. Credential Manager supports passkey, password, and federated identity authentication (such as Sign-in with Google), stronger security, and a more consistent user experience.\n\nRequests to retrieve user credentials can fail when a user has not yet saved\ncredentials or when a user has not yet signed up to your app. In these\nsituations, use the Credentials API to retrieve sign-in hints, such as the\nuser's name and email address. Use these hints to pre-fill your app's sign-in\nand sign-up forms, speeding up your app's on-boarding process.\n\nOn Android 6.0 (Marshmallow) and newer, your app does not need to request\nany device or runtime permissions to retrieve sign-in hints with the\nCredentials API.\n\nBefore you begin\n----------------\n\n[Configure an Android Studio project](/identity/smartlock-passwords/android/get-started).\n\nRetrieve sign-in hints\n----------------------\n\nTo retrieve the sign-in hints, first configure the hint selector dialog by\ncreating a [`HintRequest`](/android/reference/com/google/android/gms/auth/api/credentials/HintRequest.Builder)\nobject. Then, pass the `HintRequest` object to\n[`CredentialsClient.getHintPickerIntent()`](/android/reference/com/google/android/gms/auth/api/credentials/CredentialsClient#getHintPickerIntent(com.google.android.gms.auth.api.credentials.HintRequest))\nto get an intent to prompt the user to choose an email address. Finally, start the\nintent with `startIntentSenderForResult()`. \n\n HintRequest hintRequest = new HintRequest.Builder()\n .setHintPickerConfig(new CredentialPickerConfig.Builder()\n .setShowCancelButton(true)\n .build())\n .setEmailAddressIdentifierSupported(true)\n .setAccountTypes(IdentityProviders.GOOGLE)\n .build();\n\n PendingIntent intent = mCredentialsClient.getHintPickerIntent(hintRequest);\n try {\n startIntentSenderForResult(intent.getIntentSender(), RC_HINT, null, 0, 0, 0);\n } catch (IntentSender.SendIntentException e) {\n Log.e(TAG, \"Could not start hint picker Intent\", e);\n }\n\nThe user is prompted to choose an email address to use.\n\nThen, in the activity's `onActivityResult()` method, retrieve the hints from the\n`Credential.EXTRA_KEY` parcel, check whether the user is in your user database,\nand start the appropriate activity with the credentials hint. \n\n```transact-sql\n@Override\npublic void onActivityResult(int requestCode, int resultCode, Intent data) {\n super.onActivityResult(requestCode, resultCode, data);\n\n if (requestCode == RC_HINT) {\n if (resultCode == RESULT_OK) {\n Credential credential = data.getParcelableExtra(Credential.EXTRA_KEY);\n Intent intent;\n // Check for the user ID in your user database.\n if (userDatabaseContains(credential.getId())) {\n intent = new Intent(this, SignInActivity.class);\n } else {\n intent = new Intent(this, SignUpNewUserActivity.class);\n }\n intent.putExtra(\"com.mycompany.myapp.SIGNIN_HINTS\", credential);\n startActivity(intent);\n } else {\n Log.e(TAG, \"Hint Read: NOT OK\");\n Toast.makeText(this, \"Hint Read Failed\", Toast.LENGTH_SHORT).show();\n }\n }\n\n ...\n\n}\n```\n\nPre-fill the sign-in form\n-------------------------\n\nIf the user is in your user database and you started your app's sign-in\nactivity, you can (optionally) check if the `Credential` object contains an ID\ntoken. If so, you can [sign in the user with the ID token](/identity/smartlock-passwords/android/idtoken-auth),\nwithout requiring the user to type a password.\n\nIf the `Credential` object doesn't contain an ID token (or you don't want to use\nthe ID token), pre-fill the sign-in fields with the hints that you added to the\nintent. \n\n public class SignInActivity extends Activity {\n\n @Override\n protected void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n\n Intent intent = getIntent();\n Credential credential = intent.getParcelableExtra(\"com.mycompany.myapp.SIGNIN_HINTS\");\n\n // Pre-fill ID field\n mUsernameView.setText(credential.getId());\n\n ...\n }\n\n ...\n }\n\nPre-fill the sign-up form\n-------------------------\n\nIf the user isn't in your user database and you started your app's sign-up\nactivity, pre-fill the sign-up fields with the sign-in hints that you added to\nthe intent. \n\n public class SignUpNewUserActivity extends Activity {\n\n @Override\n protected void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n\n Intent intent = getIntent();\n Credential credential = intent.getParcelableExtra(\"com.mycompany.myapp.SIGNIN_HINTS\");\n\n // Pre-fill sign-up fields\n mUsernameView.setText(credential.getId());\n mDisplaynameView.setText(credential.getName()); // Might be null.\n\n ...\n }\n\n ...\n }\n\nOptionally, you can also check if the `Credential` object contains an\n[ID token](/identity/smartlock-passwords/android/idtoken-auth) that has a\nverified email address. If so, you can skip your app's email verification step,\nsince the email address has already been verified by Google."]]