با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
زمانی که کاربر هنوز اعتبارنامه را ذخیره نکرده باشد یا زمانی که کاربر هنوز در برنامه شما ثبت نام نکرده باشد، درخواست برای بازیابی اطلاعات کاربری ممکن است با شکست مواجه شود. در این شرایط، از Credentials API برای بازیابی نکات ورود به سیستم، مانند نام و آدرس ایمیل کاربر استفاده کنید. از این نکات برای پر کردن فرم های ورود و ثبت نام برنامه خود از قبل استفاده کنید و روند ورود به برنامه خود را سرعت بخشید.
در Android 6.0 (Marshmallow) و جدیدتر، برنامه شما نیازی به درخواست هیچ دستگاه یا مجوز زمان اجرا برای بازیابی نکات ورود به سیستم با Credentials API ندارد.
برای بازیابی نکات ورود به سیستم، ابتدا با ایجاد یک شی HintRequest ، کادر محاوره انتخابگر راهنمایی را پیکربندی کنید. سپس، شی HintRequest را به CredentialsClient.getHintPickerIntent() ارسال کنید تا یک intent دریافت کنید که از کاربر خواسته شود یک آدرس ایمیل را انتخاب کند. در نهایت، intent را با startIntentSenderForResult() شروع کنید.
از کاربر خواسته می شود تا یک آدرس ایمیل را برای استفاده انتخاب کند.
سپس، در متد onActivityResult() فعالیت، نکات را از بسته Credential.EXTRA_KEY بازیابی کنید، بررسی کنید که آیا کاربر در پایگاه داده کاربر شما قرار دارد یا خیر، و فعالیت مناسب را با اشاره اعتبار شروع کنید.
@OverridepublicvoidonActivityResult(intrequestCode,intresultCode,Intentdata){super.onActivityResult(requestCode,resultCode,data);if(requestCode==RC_HINT){if(resultCode==RESULT_OK){Credentialcredential=data.getParcelableExtra(Credential.EXTRA_KEY);Intentintent;//CheckfortheuserIDinyouruserdatabase.if(userDatabaseContains(credential.getId())){intent=newIntent(this,SignInActivity.class);}else{intent=newIntent(this,SignUpNewUserActivity.class);}intent.putExtra("com.mycompany.myapp.SIGNIN_HINTS",credential);startActivity(intent);}else{Log.e(TAG,"Hint Read: NOT OK");Toast.makeText(this,"Hint Read Failed",Toast.LENGTH_SHORT).show();}}...}
فرم ورود را از قبل پر کنید
اگر کاربر در پایگاه داده کاربر شما است و شما فعالیت ورود به سیستم برنامه خود را شروع کرده اید، می توانید (اختیاری) بررسی کنید که آیا شی Credential حاوی یک نشانه ID است یا خیر. در این صورت، می توانید بدون نیاز به تایپ رمز عبور، کاربر را با شناسه شناسه وارد کنید .
اگر شی Credential حاوی یک نشانه ID نیست (یا نمیخواهید از نشانه ID استفاده کنید)، فیلدهای ورود به سیستم را با نکاتی که به intent اضافه کردهاید از قبل پر کنید.
اگر کاربر در پایگاه داده کاربر شما نیست و شما فعالیت ثبت نام برنامه خود را شروع کرده اید، فیلدهای ثبت نام را از قبل با نکات ورود به سیستمی که به intent اضافه کرده اید پر کنید.
به صورت اختیاری، همچنین می توانید بررسی کنید که آیا شی Credential حاوی یک رمز شناسه است که یک آدرس ایمیل تأیید شده دارد یا خیر. در این صورت، میتوانید مرحله تأیید ایمیل برنامه خود را رد کنید، زیرا آدرس ایمیل قبلاً توسط Google تأیید شده است.
تاریخ آخرین بهروزرسانی 2025-07-25 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","easyToUnderstand","thumb-up"],["مشکلم را برطرف کرد","solvedMyProblem","thumb-up"],["غیره","otherUp","thumb-up"]],[["اطلاعاتی که نیاز دارم وجود ندارد","missingTheInformationINeed","thumb-down"],["بیشازحد پیچیده/ مراحل بسیار زیاد","tooComplicatedTooManySteps","thumb-down"],["قدیمی","outOfDate","thumb-down"],["مشکل ترجمه","translationIssue","thumb-down"],["مشکل کد / نمونهها","samplesCodeIssue","thumb-down"],["غیره","otherDown","thumb-down"]],["تاریخ آخرین بهروزرسانی 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."]]