-
Notifications
You must be signed in to change notification settings - Fork 267
Description
dependent Sdk Version:
implementation "androidx.credentials:credentials:1.3.0-rc01"
implementation "androidx.credentials:credentials-play-services-auth:1.3.0-rc01"
implementation "com.google.android.libraries.identity.googleid:googleid:1.1.1"
Test model:
OPPO PDKM00 Android12
Problem occurred:
GetCredentialException,
During begin sign in, failure response from one tap: 16: [28433] Cannot find a matching credential.
android.credentials.GetCredentialException.TYPE_NO_CREDENTIAL
Operation steps when a problem occurs:
Step 1:
Open phone settings->User and Account->Password and account Delete Google account
Step 2:
Refer to the official documentation to log in to Google
https://developer.android.com/identity/sign-in/credential-manager-siwg#siwg-button
The code is as follows:
private var mCm: CredentialManager? = null
fun initLogin(activity : FragmentActivity?){
mCm = CredentialManager.create(this)
}
fun login(activity : FragmentActivity?){
activity?.apply {
val googleIdOption: GetGoogleIdOption = GetGoogleIdOption.Builder()
.setFilterByAuthorizedAccounts(true)
.setServerClientId(serviceClientId)
.setAutoSelectEnabled(true)
.build()
val request: GetCredentialRequest = GetCredentialRequest.Builder()
.addCredentialOption(googleIdOption)
.build()
lifecycleScope.launch {
try {
val result = mCm?.getCredential(
request = request,
context = this@apply,
)
handleSignIn(result,this@apply)
} catch (e: GetCredentialException) {
**// During begin sign in, failure response from one tap: 16: [28433] Cannot find a matching credential.**
handleFailure(e)
**loginAgain(activity)**
}
}
}
}
fun loginAgain(activity : FragmentActivity?){
activity?.apply {
val googleIdOption: GetGoogleIdOption = GetGoogleIdOption.Builder()
**.setFilterByAuthorizedAccounts(false)**
.setServerClientId(defaultServiceClientId)
.build()
val request: GetCredentialRequest = GetCredentialRequest.Builder()
.addCredentialOption(googleIdOption)
.build()
lifecycleScope.launch {
try {
val result = mCm?.getCredential(
request = request,
context = this@apply,
)
handleSignIn(result,this@apply)
} catch (e: GetCredentialException) {
**// During begin sign in, failure response from one tap: 16: [28433] Cannot find a matching credential.**
}
}
}
}
Expected results:
If none are found, prompt the user to sign up with their Google Account using setFilterByAuthorizedAccounts(false);
pop-up interface for entering Google account:
Actual results:
Following the instructions in the document,
If no saved credentials are found (no Google Accounts returned by getGoogleIdOption), prompt your user to sign up. First, check if setFilterByAuthorizedAccounts(true) to see if any previously used accounts exist. If none are found, prompt the user to sign up with their Google Account using setFilterByAuthorizedAccounts(false);
an error still occurs,No pop-up interface for entering Google account:
exception occurred GetCredentialException,
During begin sign in, failure response from one tap: 16: [28433] Cannot find a matching credential;
android.credentials.GetCredentialException.TYPE_NO_CREDENTIAL;