Android自动填充: dispatchProvideAutofillStructure() not laid out

标签 android android-logcat autofill android-8.0-oreo

我已将我的应用配置为使用 compileSdkVersion 26 支持 Android Oreo。我还为我的电话号码输入字段设置了 android:autofillHints="phone"。当我点击该字段时,我可以看到 “自动填充” 弹出。但是,当我点击 "Autofill" 时,"Contents can't be autofill" toast 出现,我在 logcat 中看到以下跟踪:

RemoteFillService  Not handling { when=-3ms what=3 target=com.android.internal.os.HandlerCaller$MyHandler } as service for ComponentInfo{com.google.android.gms/com.google.android.gms.autofill.service.AutofillService} is already destroyed
View               dispatchProvideAutofillStructure(): not laid out, ignoring

我应该如何解决这个问题?我已确认我已在 设置 > 系统 > 语言和输入 > 高级 > 输入帮助 > 自动填充服务中配置了电话号码

使用示例 XML 更新:在 API 26 模拟器设置中,我可以选择“使用 Google 自动填充”。使用Android Studio的Design选项卡,我添加了一个"Phone"类型EditText,然后手动插入android:autofillHints="phone" XML 元素:

<EditText
    android:id="@+id/editText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="phone"
    android:autofillHints="phone" />

使用此 XML 可以观察到上述 Logcat 特性。

最佳答案

我是负责自动填充框架项目的 Android 框架工程师,所以我会回答一些问题:

  • “无法自动填充内容” 消息通常表示自动填充服务不知道如何自动填充屏幕。当您向应用程序添加自动填充支持时,使用您可以首先控制的自动填充服务通常更容易,而不是像密码管理器这样的“真实”服务。正如之前的回复中提到的,我们提供了 sample service可用于此目的。
  • 当您长按文本字段并选择 AUTOFILL 时,您实际上是在“强制”自动填充请求,正如另一个回复中提到的那样(即,在幕后,文本字段正在调用 AutofillManager.requestAutofill())。如果自动填充服务知道如何自动填充您的屏幕,则您不需要这样做,因为一旦您关注输入字段,自动填充建议就会立即显示。
  • 在您的情况下,您不需要设置 importantForAutofill 或调用 AutofillManager.cancel()

因此,我的建议是先尝试使用示例自动填充服务实现来测试您的应用。最有可能的是,当您第一次访问您的应用程序时,不会显示自动填充弹出窗口,因为该服务没有数据。但是,一旦您的应用程序触发了保存 UI(例如,在您手动输入电话号码并且 Activity 完成后)并点击保存,则该数据应该在您下次启动 Activity 时可用。

希望对你有帮助,

-- 费利佩

关于Android自动填充: dispatchProvideAutofillStructure() not laid out,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45627420/

相关文章:

android - 无法执行 Maven 全新安装

java - 关于 RadioGroup 处理的困惑

android - 从 Android 中的多个蓝牙设备读取?

android - (httplog)-静态 : issbsettingenabled false android

html - 使用 HTML/CSS 覆盖浏览器表单填写和输入突出显示

javascript - 将变量从php传递到js?或者更好的方法?

java - 如何在 ListView 中显示多个图像?

java - 尝试在 Android 中生成 PDF 时出现 FileNotFoundException

java - Android - 获取所有联系人列表时出错

python - 将行添加到数据框以统一组的长度