ย้ายข้อมูลจาก Smart Lock สำหรับรหัสผ่านไปยังเครื่องมือจัดการข้อมูลเข้าสู่ระบบ
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
Smart Lock สำหรับรหัสผ่าน ซึ่งเลิกใช้งานในปี 2022 ถูกนำออกจาก Google Play Services Auth SDK
(com.google.android.gms:play-services-auth
) แล้วตอนนี้ ความสามารถของ Smart Lock สำหรับแอปทั้งหมดที่มีอยู่ใน Play Store จะทำงานอย่างถูกต้องต่อไป ทั้งนี้เพื่อลดการเปลี่ยนแปลงที่อาจส่งผลกับส่วนอื่นในการผสานรวมที่มีอยู่ให้น้อยที่สุด แอปเวอร์ชันใหม่ๆ ที่คอมไพล์ด้วย SDK ที่อัปเดตแล้ว (com.google.android.gms:play-services-auth:21.0.0
) จะไม่สามารถเข้าถึง Smart Lock สำหรับ Password API ได้อีกต่อไปและจะสร้างไม่สำเร็จ นักพัฒนาแอปทุกคนควรย้ายข้อมูลโปรเจ็กต์ Android ไปใช้ Credential Manager โดยเร็วที่สุด
ประโยชน์ของการย้ายข้อมูลไปยัง Credential Manager API
เครื่องมือจัดการข้อมูลเข้าสู่ระบบมี API แบบรวมที่ใช้งานง่ายซึ่งรองรับฟีเจอร์และแนวทางปฏิบัติสมัยใหม่ ในขณะเดียวกันก็ปรับปรุงประสบการณ์การตรวจสอบสิทธิ์ให้กับผู้ใช้ด้วย
- เครื่องมือจัดการข้อมูลเข้าสู่ระบบรองรับการบันทึกรหัสผ่านและการตรวจสอบสิทธิ์อย่างเต็มรูปแบบ
ซึ่งหมายความว่าผู้ใช้จะไม่พบการหยุดชะงักขณะที่แอปย้ายข้อมูลจาก Smart Lock ไปยังเครื่องมือจัดการข้อมูลเข้าสู่ระบบ
- Credential Manager ผสานรวมการรองรับวิธีการลงชื่อเข้าใช้หลายวิธี ซึ่งรวมถึงพาสคีย์และวิธีการลงชื่อเข้าใช้แบบรวมศูนย์ เช่น ลงชื่อเข้าใช้ด้วย Google เพื่อเพิ่มความปลอดภัยและเปิดใช้ Conversion หากคุณวางแผนที่จะรองรับวิธีการดังกล่าวในอนาคต
- ตั้งแต่ Android 14 เป็นต้นไป เครื่องมือจัดการข้อมูลเข้าสู่ระบบจะรองรับผู้ให้บริการรหัสผ่านและพาสคีย์ของบุคคลที่สาม
- เครื่องมือจัดการข้อมูลเข้าสู่ระบบมอบประสบการณ์การใช้งานที่สอดคล้องกันและรวมเป็นหนึ่งเดียวสำหรับวิธีตรวจสอบสิทธิ์ทั้งหมด
ตัวเลือกการย้ายข้อมูล
ลงชื่อเข้าใช้ด้วยรหัสผ่านโดยใช้เครื่องมือจัดการข้อมูลเข้าสู่ระบบ
หากต้องการใช้ Credential Manager API ให้ทําตามขั้นตอนที่ระบุไว้ในส่วนข้อกําหนดเบื้องต้นของคู่มือ Credential Manager และตรวจสอบว่าคุณได้ทำสิ่งต่อไปนี้
ลงชื่อเข้าใช้ด้วยรหัสผ่านที่บันทึกไว้
หากต้องการเรียกดูตัวเลือกรหัสผ่านที่เชื่อมโยงกับบัญชีของผู้ใช้ ให้ทำตามขั้นตอนต่อไปนี้
1. เริ่มต้นรหัสผ่านและตัวเลือกการตรวจสอบสิทธิ์
// Retrieves the user's saved password for your app from their
// password provider.
val getPasswordOption = GetPasswordOption()
2. ใช้ตัวเลือกที่ดึงมาจากขั้นตอนก่อนหน้าเพื่อสร้างคําขอลงชื่อเข้าใช้
val getCredRequest = GetCredentialRequest(
listOf(getPasswordOption)
)
3. เปิดขั้นตอนการลงชื่อเข้าใช้
fun launchSignInFlow() {
coroutineScope.launch {
try {
// Attempt to retrieve the credential from the Credential Manager.
val result = credentialManager.getCredential(
// Use an activity-based context to avoid undefined system UI
// launching behavior.
context = activityContext,
request = getCredRequest
)
// Process the successfully retrieved credential.
handleSignIn(result)
} catch (e: GetCredentialException) {
// Handle any errors that occur during the credential retrieval
// process.
handleFailure(e)
}
}
}
private fun handleSignIn(result: GetCredentialResponse) {
// Extract the credential from the response.
val credential = result.credential
// Determine the type of credential and handle it accordingly.
when (credential) {
is PasswordCredential -> {
val username = credential.id
val password = credential.password
// Use the extracted username and password to perform
// authentication.
}
else -> {
// Handle unrecognized credential types.
Log.e(TAG, "Unexpected type of credential")
}
}
}
private fun handleFailure(e: GetCredentialException) {
// Handle specific credential retrieval errors.
when (e) {
is GetCredentialCancellationException -> {
/* This exception is thrown when the user intentionally cancels
the credential retrieval operation. Update the application's state
accordingly. */
}
is GetCredentialCustomException -> {
/* This exception is thrown when a custom error occurs during the
credential retrieval flow. Refer to the documentation of the
third-party SDK used to create the GetCredentialRequest for
handling this exception. */
}
is GetCredentialInterruptedException -> {
/* This exception is thrown when an interruption occurs during the
credential retrieval flow. Determine whether to retry the
operation or proceed with an alternative authentication method. */
}
is GetCredentialProviderConfigurationException -> {
/* This exception is thrown when there is a mismatch in
configurations for the credential provider. Verify that the
provider dependency is included in the manifest and that the
required system services are enabled. */
}
is GetCredentialUnknownException -> {
/* This exception is thrown when the credential retrieval
operation fails without providing any additional details. Handle
the error appropriately based on the application's context. */
}
is GetCredentialUnsupportedException -> {
/* This exception is thrown when the device does not support the
Credential Manager feature. Inform the user that credential-based
authentication is unavailable and guide them to an alternative
authentication method. */
}
is NoCredentialException -> {
/* This exception is thrown when there are no viable credentials
available for the user. Prompt the user to sign up for an account
or provide an alternative authentication method. Upon successful
authentication, store the login information using
androidx.credentials.CredentialManager.createCredential to
facilitate easier sign-in the next time. */
}
else -> {
// Handle unexpected exceptions.
Log.w(TAG, "Unexpected exception type: ${e::class.java.name}")
}
}
}
แหล่งข้อมูลเพิ่มเติม
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-29 UTC
[[["เข้าใจง่าย","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-29 UTC"],[],[],null,["# Migrate from Smart Lock for Passwords to Credential Manager\n\n[Smart Lock for Passwords](https://developers.google.com/identity/smartlock-passwords/android/overview), which was deprecated in 2022, is now\nremoved from the [Google Play Services Auth SDK](https://maven.google.com/web/index.html?q=play-services-auth#com.google.android.gms:play-services-auth)\n(`com.google.android.gms:play-services-auth`) . To minimize breaking changes\nthat may impact existing integrations, Smart Lock capabilities for all existing\napps in the Play Store will continue to work correctly. New app versions\ncompiled with the updated SDK\n(`com.google.android.gms:play-services-auth:21.0.0`) are no longer able to\naccess the Smart Lock for Password API and won't build successfully. All\ndevelopers should migrate their Android projects to use [Credential Manager](/training/sign-in/passkeys)\nas soon as possible.\n\nBenefits of migration to the Credential Manager API\n---------------------------------------------------\n\nCredential Manager offers a simple, unified API that enables support for modern\nfeatures and practices while improving the authentication experience for your\nusers:\n\n- Credential Manager fully [supports password saving and authentication](/training/sign-in/passkeys). This means no interruption for your users as your app migrates from Smart Lock to Credential Manager.\n- Credential Manager integrates support for multiple sign in methods, including [passkeys](https://developers.google.com/identity/passkeys) and federated sign in methods like [Sign\n in with Google](/training/sign-in/credential-manager), to increase security and enable conversion if you plan to support either in the future.\n- Starting with Android 14, Credential Manager supports third-party password and passkey providers.\n- Credential Manager provides a consistent, unified [user experience](/design/ui/mobile/guides/patterns/passkeys) across all authentication methods.\n\n**Migration options**:\n\n| Use case | Recommendation |\n|-----------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Save password and sign in with saved password | Use the password option from the [Sign in your user with Credential Manager](/training/sign-in/passkeys) guide. The detailed steps for password saving and authentication are described later. |\n| Sign in with Google | Follow the [Integrate Credential Manager with Sign in with Google](/training/sign-in/credential-manager) guide. |\n| Show Phone number hint to users | Use the [Phone Number Hint API](https://developers.google.com/identity/phone-number-hint/android) from Google Identity Services. |\n\nSign in with passwords using Credential Manager\n-----------------------------------------------\n\nTo use Credential Manager API, complete the steps outlined in the\n[prerequisites](/training/sign-in/passkeys#prerequisites) section of the Credential Manager guide, and make sure you do\nthe following:\n\n- [Add required dependencies](/training/sign-in/passkeys#add-dependencies)\n- [Preserve classes in the ProGuard file](/training/sign-in/passkeys#proguard)\n- [Add support for Digital Asset Links](/training/sign-in/passkeys#add-support-dal) (this step should be already implemented if you are using Smart Lock for Passwords)\n- [Configure Credentials Manager](/training/sign-in/passkeys#configure)\n- [Indicate credential fields](/training/sign-in/passkeys#indicate_credential_fields)\n- [Save a user's password](/training/sign-in/passkeys#save-password)\n\nSign in with saved passwords\n----------------------------\n\nTo retrieve password options that are associated with the user's account,\ncomplete these steps:\n\n1. Initialize the password and authentication option \n\n // Retrieves the user's saved password for your app from their\n // password provider.\n val getPasswordOption = GetPasswordOption()\n\n2. Use the options retrieved from the previous step to build the sign-in\nrequest \n\n val getCredRequest = GetCredentialRequest(\n listOf(getPasswordOption)\n )\n\n3. Launch the sign-in flow \n\n fun launchSignInFlow() {\n coroutineScope.launch {\n try {\n // Attempt to retrieve the credential from the Credential Manager.\n val result = credentialManager.getCredential(\n // Use an activity-based context to avoid undefined system UI\n // launching behavior.\n context = activityContext,\n request = getCredRequest\n )\n\n // Process the successfully retrieved credential.\n handleSignIn(result)\n } catch (e: GetCredentialException) {\n // Handle any errors that occur during the credential retrieval\n // process.\n handleFailure(e)\n }\n }\n }\n\n private fun handleSignIn(result: GetCredentialResponse) {\n // Extract the credential from the response.\n val credential = result.credential\n\n // Determine the type of credential and handle it accordingly.\n when (credential) {\n is PasswordCredential -\u003e {\n val username = credential.id\n val password = credential.password\n\n // Use the extracted username and password to perform\n // authentication.\n }\n\n else -\u003e {\n // Handle unrecognized credential types.\n Log.e(TAG, \"Unexpected type of credential\")\n }\n }\n }\n\n private fun handleFailure(e: GetCredentialException) {\n // Handle specific credential retrieval errors.\n when (e) {\n is GetCredentialCancellationException -\u003e {\n /* This exception is thrown when the user intentionally cancels\n the credential retrieval operation. Update the application's state\n accordingly. */\n }\n\n is GetCredentialCustomException -\u003e {\n /* This exception is thrown when a custom error occurs during the\n credential retrieval flow. Refer to the documentation of the\n third-party SDK used to create the GetCredentialRequest for\n handling this exception. */\n }\n\n is GetCredentialInterruptedException -\u003e {\n /* This exception is thrown when an interruption occurs during the\n credential retrieval flow. Determine whether to retry the\n operation or proceed with an alternative authentication method. */\n }\n\n is GetCredentialProviderConfigurationException -\u003e {\n /* This exception is thrown when there is a mismatch in\n configurations for the credential provider. Verify that the\n provider dependency is included in the manifest and that the\n required system services are enabled. */\n }\n\n is GetCredentialUnknownException -\u003e {\n /* This exception is thrown when the credential retrieval\n operation fails without providing any additional details. Handle\n the error appropriately based on the application's context. */\n }\n\n is GetCredentialUnsupportedException -\u003e {\n /* This exception is thrown when the device does not support the\n Credential Manager feature. Inform the user that credential-based\n authentication is unavailable and guide them to an alternative\n authentication method. */\n }\n\n is NoCredentialException -\u003e {\n /* This exception is thrown when there are no viable credentials\n available for the user. Prompt the user to sign up for an account\n or provide an alternative authentication method. Upon successful\n authentication, store the login information using\n androidx.credentials.CredentialManager.createCredential to\n facilitate easier sign-in the next time. */\n }\n\n else -\u003e {\n // Handle unexpected exceptions.\n Log.w(TAG, \"Unexpected exception type: ${e::class.java.name}\")\n }\n }\n }\n\nAdditional resources\n--------------------\n\n- [Credential Manager sample reference](https://github.com/android/identity-samples/tree/glitch_me_version/CredentialManager)\n- [Credential Manager codelab](https://codelabs.developers.google.com/credential-manager-api-for-android#0)\n- [Sign in your user with Credential Manager](/training/sign-in/passkeys)"]]