// Retrieves the user's saved password for your app.valgetPasswordOption=GetPasswordOption()// Get a passkey from the user's public key credential provider.valgetPublicKeyCredentialOption=GetPublicKeyCredentialOption(requestJson=requestJson)valgetCredRequest=GetCredentialRequest(listOf(getPasswordOption,getPublicKeyCredentialOption))
จากนั้นเรียกใช้ getCredential API ซึ่งจะแสดงตัวเลือก
เครื่องมือจัดการข้อมูลเข้าสู่ระบบ
coroutineScope{try{valresult=credentialManager.getCredential(context=activityContext,// Use an activity-based context.request=getCredRequest)handleSignIn(result)}catch(e:GetCredentialException){handleFailure(e)}}
[[["เข้าใจง่าย","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-08-27 UTC"],[],[],null,["Starting with Android 15 Beta 2, paired with\n[androidx.credentials:1.5.0-alpha01](/jetpack/androidx/releases/credentials#version_15_2), developers can link specific views like\nusername or password fields with Credential Manager requests. When the user\nfocuses on one of these views, the corresponding request is sent to Credential\nManager. The resulting credentials are aggregated across providers and displayed\nin autofill UIs, such as keyboard inline suggestions, or drop-down suggestions.\nThis feature can be used as a fallback when users accidentally dismiss the\nCredential Manager account selector and then tap on the relevant fields.\n\nThe ***Jetpack androidx.credentials*** library is the preferred endpoint for\ndevelopers to use for this feature.\n\n\u003cbr /\u003e\n\n\n**Figure 1:** Autofill results with credentials using password, passkey, and\nSign in with Google.\n| **Note:** This feature is only available for `View` objects at this time.\n\nImplementation\n\nTo use Credential Manager to show credentials in autofill results, use the\n[standard implementation](/identity/sign-in/credential-manager) to build a `GetCredentialRequest` and then set it\nto the relevant views. The response handling is the same, whether the response\ncomes from the `getCredential` API call or the `PendingGetCredentialRequest`, as\nshown in the following example.\n\nFirst, construct a `GetCredentialRequest`: \n\n // Retrieves the user's saved password for your app.\n val getPasswordOption = GetPasswordOption()\n\n // Get a passkey from the user's public key credential provider.\n val getPublicKeyCredentialOption = GetPublicKeyCredentialOption(\n requestJson = requestJson\n )\n\n val getCredRequest = GetCredentialRequest(\n listOf(getPasswordOption, getPublicKeyCredentialOption)\n )\n\nNext, call the `getCredential` API. This displays the Credential Manager\nselector. \n\n coroutineScope {\n try {\n val result = credentialManager.getCredential(\n context = activityContext, // Use an activity-based context.\n request = getCredRequest\n )\n handleSignIn(result)\n } catch (e: GetCredentialException) {\n handleFailure(e)\n }\n }\n\nFinally, enable the autofill experience. Set the `getCredRequest` to relevant\nviews (such as `username, password`) to enable credential results in autofill\nwhen the user interacts with these views.\n**Note:** The `setPendingGetCredentialRequest` is an *extension API* in the androidx.credentials library, and is called differently between Kotlin and Java. \n\n usernameEditText.pendingGetCredentialRequest = PendingGetCredentialRequest(\n getCredRequest\n ) { response -\u003e\n handleSignIn(response)\n }\n\n passwordEditText.pendingGetCredentialRequest = PendingGetCredentialRequest(\n getCredRequest\n ) { response -\u003e\n handleSignIn(response)\n }"]]