【问题标题】:Save for autofill dialog not showing up保存自动填充对话框未显示
【发布时间】:2019-11-21 17:12:30
【问题描述】:

我有一个显示用户名 UI 的活动,输入后点击继续按钮会显示输入密码 UI。输入密码并点击登录按钮完成当前活动并启动新活动。在我的设备上,我选择了 Google 自动填充服务,所以在第一个活动完成后我想要“保存自动填充?”对话框显示,但它不是。我通过在我的活动中添加 autofillHints 而没有其他任何内容来准备我的应用程序。我应该为弹出的对话框添加任何内容吗?

【问题讨论】:

  • 同样的问题,你解决了吗?

标签: android autofill android-autofill-manager


【解决方案1】:

尽管遵循了文档并将 autofillHints 添加到我的布局中,但我在模拟器上遇到了类似的行为,在使用 Google 自动填充服务时调用 AutofillManager.commit() 并没有触发保存 UI。

FWIW,我从模拟器切换到物理设备,保存 UI 开始正常触发,即使我没有对我的实现进行任何更改。在这两种情况下,我都登录了 Google 帐户,并且在这两种情况下,Google 的示例调试自动填充服务都正确触发了保存 UI。

我注意到您说的是“设备”,所以这可能不适用于您,但如果您使用的是模拟器,那么在物理设备上进行测试可能值得一试,而且似乎没有其他解释说明原因它不会显示。

【讨论】:

    【解决方案2】:

    我遇到了与您的情况类似的问题,请找到解决方案:

    1- 确保您为清单添加了以下权限:

        <uses-permission
        android:name="android.permission.BIND_AUTOFILL_SERVICE"
        tools:ignore="ProtectedPermissions" />
    

    2- 假设在您的登录屏幕中有三个EditText(用户名、密码和验证码),因此您必须为屏幕中的所有编辑文本添加android:importantForAutofill。如果你错过了添加它(例如验证码,因为不需要保存它),很遗憾,自动填充对话框不会出现。

    3- 要保存用户名和密码,您应该为用户名 editText 和密码 editText 添加:

    android:importantForAutofill="yes"
    

    对于用户名editText,您应该添加:

     android:autofillHints="username"
    

    对于密码editText,您应该添加:

     android:autofillHints="password"
    

    注意: 您不应该使用textNoSuggestions 作为密码的文本输入类型:

     android:inputType="textPassword|textNoSuggestions"
    

    您应该使用:

     android:inputType="textPassword"
    

    4-你应该排除不需要的editText(Captcha)以免被保存,所以你应该添加到验证码editText:

     android:importantForAutofill="noExcludeDescendants"  
    

    5- 这是代码的 sn-p:

    com.google.android.material.textfield.TextInputLayout
                android:id="@+id/usernameTextInputLayout"
                style="@style/TextInputStyle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/margin_16"
                android:layout_marginEnd="@dimen/margin_16"
                android:layout_marginBottom="@dimen/margin_16"
                app:endIconDrawable="@drawable/ic_username"
                app:endIconMode="custom"
                app:endIconTint="?attr/theme_primary">
    
                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/usernameEditText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:autofillHints="username"
                    android:hint="@string/hint_username"
                    android:imeOptions="actionNext"
                    android:importantForAutofill="yes"
                    android:inputType="text"
                    android:maxLines="1"
                    android:textAlignment="viewStart" />
    
            </com.google.android.material.textfield.TextInputLayout>
    
            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/passwordTextInputLayout"
                style="@style/TextInputStyle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/margin_16"
                android:layout_marginEnd="@dimen/margin_16"
                android:layout_marginBottom="@dimen/margin_16"
                app:endIconDrawable="@drawable/ic_password"
                app:endIconMode="custom"
                app:endIconTint="?attr/theme_primary">
    
                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/passwordEditText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:autofillHints="password"
                    android:hint="@string/hint_password"
                    android:importantForAutofill="yes"
                    android:inputType="textPassword"
                    android:textAlignment="viewStart" />
    
            </com.google.android.material.textfield.TextInputLayout>
    
     <com.google.android.material.textfield.TextInputLayout
                    android:id="@+id/captchaTextInputLayout"
                    style="@style/TextInputStyle"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="@dimen/margin_16"
                    android:layout_marginEnd="@dimen/margin_16"
                    android:layout_marginBottom="@dimen/margin_16"
                    android:importantForAutofill="noExcludeDescendants"
                    app:boxCornerRadiusTopEnd="0dp"
                    app:boxCornerRadiusTopStart="0dp">
    
                    <com.google.android.material.textfield.TextInputEditText
                        android:id="@+id/captchaEditText"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:hint="@string/hint_captcha_input"
                        android:imeOptions="actionNext"
                        android:importantForAutofill="noExcludeDescendants"
                        android:inputType="numberDecimal"
                        android:maxLength="@integer/otp_input_length"
                        android:maxLines="1"
                        android:textAlignment="viewStart" />
    
                </com.google.android.material.textfield.TextInputLayout>
    

    【讨论】:

      【解决方案3】:

      确保在您设备的设置中也启用了 Google 自动填充功能: System &gt; Language &amp; Input &gt; Autofill Service &gt; Choose google.

      根据设备的不同,它可能位于不同的嵌套设置页面中。

      如果您想创建自定义自动填充,请务必阅读 API 上的文档: https://developer.android.com/guide/topics/text/autofill

      【讨论】:

      • 我在我的问题中已经提到我选择了 Google 自动填充服务,我按照文档中给出的所有步骤操作,我在 xml 中为我的视图添加了提示,但我仍然没有看到任何对话框。
      猜你喜欢
      • 2012-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多