קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
כדי לשלב את Smart Lock לסיסמאות באפליקציה ל-Android, צריך להוסיף קריאות ל-Credentials API בתהליך ההפעלה והכניסה של האפליקציה. בתרשים הבא מוצג התהליך של אפליקציה אופיינית ל-Android שמשתמשת ב-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() ולהתחיל מתוך
הכוונה כדי לבקש מהמשתמש לבחור חשבון, ולאחר מכן להתקשר
אל getParcelableExtra(Credential.EXTRA_KEY) כדי לקבל את
הרמז לכניסה.
אם מזהה המשתמש של הרמז תואם למשתמש קיים, יש למלא את
טופס הכניסה מראש ולאפשר למשתמש להזין את הסיסמה כדי להיכנס.
אם מזהה המשתמש של הרמז לא תואם למשתמש קיים, יש למלא מראש בטופס ההרשמה את המזהה והשם של המשתמש ולאפשר למשתמש ליצור חשבון חדש.
אחרי שהמשתמש נכנס או יוצר חשבון בהצלחה, צריך לשמור את מזהה המשתמש והסיסמה באמצעות CredentialsClient.save().
אם המשתמש נכנס באמצעות ספק זהויות מאוחד, כמו כניסה באמצעות
Google, צריך ליצור את האובייקט Credential עם כתובת האימייל
של המשתמש ולהגדיר אותו כמזהה, ולציין את ספק הזהויות באמצעות
setAccountType.
יציאה
כשהמשתמש יצא מהחשבון, צריך לבצע קריאה ל-CredentialsClient.disableAutoSignIn()
כדי למנוע כניסה מיידית של המשתמש לחשבון. השבתה
של הכניסה האוטומטית מאפשרת למשתמשים לעבור בין חשבונות בקלות – למשל, בין חשבון לצורכי עבודה לחשבון לשימוש אישי, או בין חשבונות במכשירים משותפים – בלי שיצטרכו להזין מחדש את פרטי הכניסה שלהם.
רוצה לשלב את Smart Lock לסיסמאות באפליקציה?
התחל בעבודה.
[null,null,["עדכון אחרון: 2025-07-25 (שעון UTC)."],[[["\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)."]]