Skip to content

Commit 80802cb

Browse files
authored
Add remaining autofill snippet with edittext (#562)
1 parent 0c23312 commit 80802cb

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

identity/credentialmanager/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ dependencies {
7070
implementation(libs.okhttp)
7171
implementation(libs.kotlin.coroutines.okhttp)
7272
implementation(libs.androidx.webkit)
73+
implementation(libs.appcompat)
7374
debugImplementation(libs.androidx.compose.ui.tooling)
7475
debugImplementation(libs.androidx.compose.ui.test.manifest)
7576
}

identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/PasskeyAndPasswordFunctions.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import android.os.Build
2222
import android.os.Bundle
2323
import android.util.Log
2424
import androidx.annotation.RequiresApi
25+
import androidx.appcompat.widget.AppCompatEditText
2526
import androidx.credentials.CreatePasswordRequest
2627
import androidx.credentials.CreatePublicKeyCredentialRequest
2728
import androidx.credentials.CredentialManager
@@ -31,15 +32,16 @@ import androidx.credentials.GetCredentialResponse
3132
import androidx.credentials.GetPasswordOption
3233
import androidx.credentials.GetPublicKeyCredentialOption
3334
import androidx.credentials.PasswordCredential
35+
import androidx.credentials.PendingGetCredentialRequest
3436
import androidx.credentials.PublicKeyCredential
3537
import androidx.credentials.exceptions.CreateCredentialCancellationException
3638
import androidx.credentials.exceptions.CreateCredentialCustomException
3739
import androidx.credentials.exceptions.CreateCredentialException
3840
import androidx.credentials.exceptions.CreateCredentialInterruptedException
3941
import androidx.credentials.exceptions.CreateCredentialProviderConfigurationException
40-
import androidx.credentials.exceptions.CreateCredentialUnknownException
4142
import androidx.credentials.exceptions.GetCredentialException
4243
import androidx.credentials.exceptions.publickeycredential.CreatePublicKeyCredentialDomException
44+
import androidx.credentials.pendingGetCredentialRequest
4345
import kotlinx.coroutines.coroutineScope
4446
import kotlinx.coroutines.runBlocking
4547
import org.json.JSONObject
@@ -162,6 +164,19 @@ class PasskeyAndPasswordFunctions (
162164
}
163165
// [END android_identity_autofill_get_credential_api]
164166
}
167+
168+
val usernameEditText: androidx.appcompat.widget.AppCompatEditText = AppCompatEditText(activityContext)
169+
val passwordEditText: androidx.appcompat.widget.AppCompatEditText = AppCompatEditText(activityContext)
170+
171+
// [START android_identity_autofill_enable_edit_text]
172+
usernameEditText.pendingGetCredentialRequest = PendingGetCredentialRequest(
173+
getCredRequest) { response -> handleSignIn(response)
174+
}
175+
176+
passwordEditText.pendingGetCredentialRequest = PendingGetCredentialRequest(
177+
getCredRequest) { response -> handleSignIn(response)
178+
}
179+
// [END android_identity_autofill_enable_edit_text]
165180
}
166181

167182
// [START android_identity_launch_sign_in_flow_2]

0 commit comments

Comments
 (0)