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/