自动填充框架在应用中已禁用,但在其他应用中已启用

时间:2018-09-18 13:11:57

标签: android autofill android-autofill-manager

当尝试对登录片段使用自动填充框架时遇到了问题,它没有显示保存弹出窗口。我在两个文本字段上都放置了android:autofillHints属性,然后对两个文本字段都尝试了android:importantForAutofill="yes",但结果也相同,并且还尝试了手动调用AutofillManager.requestAutofill()AutofillManager.commit()

接下来,我从here下载了一个示例并安装了该示例,该示例正常运行。我使用debug来检查两个应用程序中的AutofillManager,结果发现AutofillManager.isEnabled()产生了不同的结果:示例应用程序中为true,而我的应用程序中为false。在这两种情况下,我都在应用程序的第一个活动中检查了onCreate()的第一行,这两种情况都不包含要填充的字段。

这就是为什么我认为问题不在代码或布局文件中,而是在gradle或清单文件中,但是我找不到可能影响自动填充框架的任何区别。我认为框架也没有配置值。我检查了targetSdk和minSdk,不是吗

我还应该检查什么?

2 个答案:

答案 0 :(得分:0)

AutofillManager.isEnabled()不应在您的应用程序或示例应用程序上产生不同的结果,我猜测您使用的是错误的上下文来获取管理员,应该是Activity

答案 1 :(得分:0)

您可能需要配置自动填充服务,并且需要在onProvideAutofillStructure方法中添加视图数据绑定逻辑。

<!--
Declare AutofillService implementation; only needed for a small number of apps that will
be implementing an AutofillService. Framework parses meta-data and sets the service's
Settings Activity based on what the meta-data resource points to.
-->
    <service
        android:name=".MyAutofillService"
        android:label="Multi-Dataset Autofill Service"
        android:permission="android.permission.BIND_AUTOFILL_SERVICE">
        <meta-data
            android:name="android.autofill"
            android:resource="@xml/multidataset_service" />

        <intent-filter>
            <action android:name="android.service.autofill.AutofillService" />
        </intent-filter>
    </service>