تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
لدمج 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 لكلمات المرور في تطبيقك؟
بدء الاستخدام.
تاريخ التعديل الأخير: 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)."]]