1

I am trying to use CredentialManager to save username and password. I am using xml layout and testing on Android 12, I keeping getting error saying androidx.credentials.exceptions.CreateCredentialUnknownException: During save password, found password failure response from one tap 16: [28431] Skipping password saving since the user is likely prompted with Android Autofill. When I checked the doc, it says to ignore the error but the OS never prompts me to save the credentials.

Here is the sample code

private suspend fun signUp(username: String, password: String): String {
        return try {
            //make api call to your backend and if success then
            credentialManager.createCredential(
                context = this,
                request = CreatePasswordRequest(
                    id = username,
                    password = password
                )
            )
            "Success"
        } catch (e: CreateCredentialCancellationException) {
            e.printStackTrace()
            "Cancelled"
        } catch(e: CreateCredentialException) {
            e.printStackTrace()
            Log.i("Erroris",e.toString())
            "Failure"
        }
    }

Here is my xml layout

<EditText
        android:id="@+id/username"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:autofillHints="username"
        android:inputType="text"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:ignore="LabelFor"
        android:hint="@string/username"
        android:layout_marginBottom="200dp"

        />

    <EditText
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/username"
        tools:ignore="LabelFor"
        android:autofillHints="password"
        android:hint="@string/password"
        android:id="@+id/password"
        />

Now in my xml layout I have tried couple of things like

android:importantForAutofill="no"
tools:ignore="Autofill,LabelFor"

In my code I also tried adding

val autofillManager = getSystemService(AutofillManager::class.java)
 autofillManager?.disableAutofillServices()

but the error persists

1 Answer 1

1
+50

See the Troubleshooting Guide concerning CreateCredentialUnknownException ...

This error only impacts Android 13 and earlier versions when Google is the designated Autofill provider. In such cases, users will receive a save prompt from Autofill, and the password will be stored in Google Password Manager. Importantly, credentials saved using Autofill with Google are bi-directionally synced with the Credential Manager API. Therefore, this error can be safely disregarded.

It might eventually fail when also disabling auto-fill, because then the given situation won't be "when Google is the designated Autofill provider" anymore. This must stay enabled < Android 14.


CredentialManager is entirely useless in this situation.

You could in best case try to force an autofill request on focus:

fun eventHandler(view: View) {
    val afm = requireContext().getSystemService(AutofillManager::class.java)
    afm?.requestAutofill(view)
}

The issue filed for this ultimately just redirects to the above troubleshooting guide.

Sign up to request clarification or add additional context in comments.

1 Comment

So all in all I need to buy a new device, correct? @MartinZeitler

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.