如何让用户在 android 8.0 中以编程方式自动填充框架设置屏幕

How to get the user to auto fill framework setting screen pro-grammatically in android 8.0

我想让用户进入自动填写框架设置屏幕,以使 AutoFill 框架能够自动填写第三方应用程序中的登录表单。

那么,如何以编程方式让用户进入 Oreo 设备中的自动填充设置屏幕?

先决条件:

用户必须启用自动填充服务。 设置 > 系统 > 语言和输入法 > 高级 > 输入辅助 > 自动填充服务。

1.Providing 自动填充提示

自动填充服务通过提供每个可自动填充的视图的含义来正确分类数据,例如表示用户名和密码的视图。

xml :

android:autofillHints="AUTOFILL_HINT_USERNAME"

Java :

editText.setAutofillHints(View.AUTOFILL_HINT_USERNAME);

2。强制自动填充请求

AutofillManager afm = getSystemService(AutofillManager.class);
if (afm != null) {
    if (afm.isEnabled()) {   //for afmanager is enabled or not
        afm.requestAutofill(editText);
    }
}

经过长时间的搜索,我从 github 项目中找到了答案。

让用户以编程方式自动填充设置屏幕的代码如下

   if (mAutofillManager != null && !mAutofillManager.hasEnabledAutofillServices()) {
        Intent intent = new Intent(Settings.ACTION_REQUEST_SET_AUTOFILL_SERVICE);
        intent.setData(Uri.parse("package:com.example.android"));
        startActivityForResult(intent, REQUEST_CODE_SET_DEFAULT);
    }