You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android 12使用CredentialManager保存凭据失败且无弹窗问题

问题:Android 12下CredentialManager保存凭据无弹窗且抛出特定异常

在Android 12设备上,通过XML布局配合CredentialManager实现用户名密码保存功能时,持续抛出异常:

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

查阅官方文档得知该错误可忽略,但系统从未弹出凭据保存提示。


示例代码

保存凭据的Kotlin代码

private suspend fun signUp(username: String, password: String): String {
    return try {
        //调用后端接口成功后执行
        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"
    }
}

XML布局代码

<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"
    />

已尝试的解决方案

  • 在布局的EditText中添加属性:
    android:importantForAutofill="no"
    tools:ignore="Autofill,LabelFor"
    
  • 在代码中禁用Autofill服务:
    val autofillManager = getSystemService(AutofillManager::class.java)
    autofillManager?.disableAutofillServices()
    

以上操作均未解决问题,异常仍存在且无保存弹窗。

内容的提问来源于stack exchange,提问作者BraveEvidence

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 08:27:07