با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
برای ادغام Smart Lock for Passwords در برنامه Android خود، باید تماسهایی را به Credentials API به جریان راهاندازی و ورود به برنامه خود اضافه کنید. نمودار زیر جریان یک برنامه معمولی اندروید را نشان می دهد که از Smart Lock برای رمز عبور استفاده می کند.
در حالی که راههای زیادی برای ادغام موفقیتآمیز Smart Lock برای گذرواژهها وجود دارد، و ویژگیهای یکپارچهسازی به ساختار و تجربه کاربری برنامه بستگی دارد، جریان زیر برای اکثر برنامهها توصیه میشود. برنامه هایی که از این جریان استفاده می کنند دارای مزایای تجربه کاربری زیر هستند:
کاربران موجود سرویس شما که دارای یک اعتبارنامه ذخیره شده هستند، بلافاصله وارد سیستم می شوند و با باز کردن برنامه، مستقیماً به نمای ورود به سیستم می روند.
کاربرانی که چندین اعتبار ذخیره شده دارند یا ورود به سیستم خودکار را غیرفعال کرده اند، باید قبل از رفتن به نمای ورود به سیستم برنامه، فقط به یک گفتگو پاسخ دهند.
کاربرانی که هیچ اطلاعات کاربری ذخیرهشدهای ندارند یا هنوز ثبتنام نکردهاند، میتوانند با یک ضربه نام و ایمیل خود را انتخاب کنند و با این اطلاعات از قبل پر شده، هوشمندانه به نمای ورود یا ثبتنام ارسال شوند.
وقتی کاربران از سیستم خارج میشوند، برنامه مطمئن میشود که بهطور خودکار دوباره وارد سیستم نمیشوند.
بازیابی اعتبار
هنگامی که برنامه شروع به کار کرد، اگر هیچ کاربری از قبل وارد سیستم نشده است، با CredentialsClient.request() تماس بگیرید.
اگر Task موفقیت آمیز بود، اعتبار کاربر را با getResult().getCredential() دریافت کنید و از آنها برای ورود به سیستم استفاده کنید.
اگر Task ناموفق باشد و استثنا نمونهای از ResolvableApiException باشد و getStatusCode()RESOLUTION_REQUIRED را برمیگرداند، ورودی کاربر برای انتخاب یک اعتبار مورد نیاز است. با startResolutionForResult() تماس بگیرید تا از کاربر بخواهد یک حساب ذخیره شده را انتخاب کند، سپس getParcelableExtra(Credential.EXTRA_KEY) برای دریافت اعتبار کاربر و استفاده از آنها برای ورود به سیستم تماس بگیرید.
ذخیره اعتبار
اگر Task با یک ApiException ناموفق باشد و getStatusCode()SIGN_IN_REQUIRED را برمی گرداند، کاربر هیچ اعتبارنامه ذخیره شده ای ندارد و باید با استفاده از جریان ورود یا ثبت نام فعلی شما وارد یا ثبت نام کند. پس از اینکه کاربر با موفقیت ورود به سیستم را تکمیل کرد، می توانید فرصتی را برای کاربر فراهم کنید تا اعتبار خود را برای بازیابی در آینده ذخیره کند (مرحله 5).
میتوانید با بازیابی نکات ورود به سیستم، مانند آدرس ایمیل کاربر، به کاربر کمک کنید سریعتر و راحتتر وارد سیستم یا ثبتنام شود. کاربر می تواند راهنمایی را انتخاب کرده و از تایپ اعتبار خود صرف نظر کند. اگر برنامه شما از کاربران می خواهد که وارد سیستم شوند، ممکن است بلافاصله پس از شکست درخواست اعتبارنامه اولیه، نکات را بازیابی کنید (در غیر این صورت، می توانید منتظر بمانید تا کاربر جریان ورود به سیستم یا ثبت نام را شروع کند).
CredentialsClient.getHintPickerIntent() را فراخوانی کنید و intent را برای درخواست از کاربر برای انتخاب یک حساب شروع کنید، سپس getParcelableExtra(Credential.EXTRA_KEY) برای دریافت راهنمایی ورود به سیستم فراخوانی کنید.
اگر شناسه کاربری راهنمایی با کاربر موجود مطابقت دارد، فرم ورود به سیستم را از قبل با آن پر کنید و به کاربر اجازه دهید رمز ورود را وارد کند.
اگر شناسه کاربری راهنمایی با کاربر موجود مطابقت ندارد، فرم ثبت نام را با شناسه و نام کاربر از قبل پر کنید و به کاربر اجازه دهید یک حساب کاربری جدید ایجاد کند.
پس از اینکه کاربر با موفقیت وارد سیستم شد یا یک حساب ایجاد کرد، شناسه کاربری و رمز عبور را با CredentialsClient.save() ذخیره کنید.
اگر کاربر با یک ارائه دهنده هویت فدرال مانند Google Sign-In وارد شده است، شی Credential را با آدرس ایمیل کاربر به عنوان شناسه ایجاد کنید و ارائه دهنده هویت را با setAccountType مشخص کنید.
خروج از سیستم
هنگامی که کاربر از سیستم خارج میشود، با CredentialsClient.disableAutoSignIn() تماس بگیرید تا از ورود سریع کاربر به سیستم جلوگیری کنید. غیرفعال کردن ورود به سیستم خودکار همچنین کاربران را قادر میسازد تا به راحتی بین حسابها جابهجا شوند - به عنوان مثال، بین حسابهای کاری و شخصی، یا بین حسابها در دستگاههای مشترک—بدون نیاز به وارد کردن مجدد اطلاعات ورود به سیستم.
آیا برای ادغام Smart Lock برای رمزهای عبور در برنامه خود آماده هستید؟ شروع کنید .
تاریخ آخرین بهروزرسانی 2025-07-25 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 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\u003eSmart Lock for Passwords integration involves adding the Credentials API to your app's startup and sign-in flow to retrieve and save user credentials.\u003c/p\u003e\n"],["\u003cp\u003eExisting users with saved credentials can experience automatic sign-in, while new users can benefit from pre-filled forms using sign-in hints.\u003c/p\u003e\n"],["\u003cp\u003eEnsure to disable auto-sign-in upon user sign-out to prevent immediate re-authentication and facilitate account switching.\u003c/p\u003e\n"]]],[],null,["# Android integration flow\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\nTo integrate Smart Lock for Passwords into your Android app, you must add calls\nto the [Credentials API](/android/reference/com/google/android/gms/auth/api/credentials/package-summary)\nto your app's start-up and sign-in flow. The following diagram shows the flow of\na typical Android app that uses Smart Lock for Passwords.\n\nWhile there are many ways to successfully integrate Smart Lock for Passwords,\nand the specifics of an integration depend on the structure and user experience\nof the app, the following flow is recommended for most apps. Apps that use this\nflow have these user experience advantages:\n\n- Existing users of your service that have a single credential saved are immediately signed in, and they will go directly to the signed-in view when they open the app.\n- Users that have multiple credentials saved or that have disabled automatic sign-in need to respond to only one dialog before they go to the app's signed-in view.\n- Users that have no saved credentials or haven't signed up yet can pick their name and email with a single tap and be intelligently sent to either the sign-in or sign-up view, with this information pre-filled.\n- When users sign out, the app ensures they are not automatically signed back in.\n\n[](/static/identity/smartlock-passwords/android/images/smartlock-passwords-flow.png)\n\n### Retrieve credentials\n\n1. When the app starts, if no user is already signed in, call `CredentialsClient.request()`.\n2. If the `Task` is successful, get the user's credentials with `getResult().getCredential()` and use them to sign in.\n3. If the `Task` fails and the exception is an instance of `ResolvableApiException` and `getStatusCode()` returns `RESOLUTION_REQUIRED`, user input is required to pick a credential. Call `startResolutionForResult()` to prompt the user to select a saved account, then call `getParcelableExtra(Credential.EXTRA_KEY)` to get the user's credentials and use them to sign in. If signing in with the retrieved credentials fails because the password is incorrect or the account doesn't exist, delete the credentials from Smart Lock with `CredentialsClient.delete()`.\n\n### Save credentials\n\n4. If the `Task` fails with an `ApiException` and\n `getStatusCode()` returns `SIGN_IN_REQUIRED`, the\n user has no saved credentials and must sign in or sign up manually using\n your current sign-in or sign-up flow. After the user successfully\n completes sign in, you can provide an opportunity for the user to save\n their credentials for future retrieval (step 5).\n\n You can help the user sign in or sign up faster and more\n easily by retrieving sign-in hints, such as the user's email address. The\n user can select the hint and skip typing their credentials. If your app\n requires users to sign in, you might choose to retrieve hints immediately\n after the initial credentials request fails (otherwise, you can wait until\n the user starts the sign-in or sign-up flow).\n 1. Call `CredentialsClient.getHintPickerIntent()` and start the intent to prompt the user to select an account, then call `getParcelableExtra(Credential.EXTRA_KEY)` to get the sign-in hint.\n 2. If the user ID of the hint matches an existing user, pre-fill the sign-in form with it and let the user enter the password to sign in.\n 3. If the user ID of the hint doesn't match an existing user, pre-fill the sign-up form with the user's ID and name, and let the user create a new account.\n5. After the user successfully signs in or creates an account, save the user\n ID and password with `CredentialsClient.save()`.\n\n If the user signed in with a federated identity provider such as Google\n Sign-In, create the `Credential` object with the user's email\n address as the ID and specify the identity provider with\n `setAccountType`.\n\n### Sign out\n\n6. When the user signs out, call `CredentialsClient.disableAutoSignIn()` to prevent the user from being immediately signed back in. Disabling auto-sign-in also enables users to switch between accounts easily---for example, between work and personal accounts, or between accounts on shared devices---without having to re-enter their sign-in information.\n\nReady to integrate Smart Lock for Passwords into your app?\n[Get started](/identity/smartlock-passwords/android/get-started)."]]