gpt4 book ai didi

android - 禁用应用程序的 Android O 自动填充服务

转载 作者:IT老高 更新时间:2023-10-28 21:46:14 29 4
gpt4 key购买 nike

Android O 具有支持 Auto-filling 的功能对于字段。有什么方法可以为特定应用程序禁用它。那就是我想强制我的应用程序不使用自动填充服务。

有可能吗?

要阻止整个 Activity 的自动填充,请在 Activity 的 onCreate() 中使用它:

getWindow()
.getDecorView()
.setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS);

还有比这更好的方法吗?

最佳答案

目前没有直接的方法来禁用整个应用程序的自动填充,因为自动填充功能是特定于 View 的。

您仍然可以尝试这种方式并在任何地方调用 BaseActivity。

public class BaseActivity extends AppCompatActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
disableAutofill();
}

@TargetApi(Build.VERSION_CODES.O)
private void disableAutofill() {
getWindow().getDecorView().setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS);
}
}

您也可以通过这种方式强制请求自动填充。

public void forceAutofill() {
AutofillManager afm = context.getSystemService(AutofillManager.class);
if (afm != null) {
afm.requestAutofill();
}
}

注意:目前自动填充功能仅在API 26 Android Oreo 8.0

中可用

希望这会有所帮助!

关于android - 禁用应用程序的 Android O 自动填充服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45731372/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com