天道酬勤,学无止境

Disabling Android O auto-fill service for an application

Android O has the feature to support Auto-filling for fields. Is there any way I can disable it for a specific application. That is I want to force my application not to use the auto-fill service.

Is it possible ?

To block autofill for an entire activity, use this in onCreate() of the activity:

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

Is there any better method than this ?

评论

Is it possible ?

Not that I am aware of. Certainly, nothing is documented.

Is there any better method than this ?

Not that I am aware of.

Currently there is no direct way to disable the autofill for an entire application, since the autofill feature is View specific.

You can still try this way and call BaseActivity everywhere.

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);
    }
}

You can also force request autofill this way.

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

Note: At the moment autofill feature is only available in API 26 Android Oreo 8.0

Hope this helps!

I believe the accepted answer is incorrect:

So I have my own class which is extends the android.support.v7.widget.AppCompatEditText and all I did is overwrote the following method with the following value:

@Override
public int getAutofillType() {
    return AUTOFILL_TYPE_NONE;
}

no other solutions worked, not even android:importantForAutofill="no".

getAutofillType() comes from the View class, so it should work for every other class such as TextInputEditText too!

I ran into this too. It turns out the issue was caused by setting the hint text on the EditText nested inside the TextInputLayout.

I did some digging and found this nugget in the 26.0.0 Beta 2 release notes. Andorid Support Release Notes June 2017

TextInputLayout must set hints on onProvideAutofillStructure()

That led me to try setting the hint on the TextInputLayout instead of the nested EditText.

This resolved the crashing issue for me. Example:

            <android.support.design.widget.TextInputLayout
                android:id="@+id/textInputLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Some Hint Text"
                android.support.design:hintAnimationEnabled="true"
                android.support.design:hintEnabled="true"
                android.support.design:layout_marginTop="16dp">

                <android.support.design.widget.TextInputEditText
                    android:id="@+id/editText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"/>

            </android.support.design.widget.TextInputLayout>

Seems to be a bug that needs to be fixed : https://issuetracker.google.com/issues/67675432
In the meanwhile a workaround for now is to disable the AutoFill feature for the whole project. You can add in the values-v26/styles.xml file the following style or you can edit your BaseEditTextStyle if you are using a specific style for your EditText views.

<style name="App_EditTextStyle" parent="@android:style/Widget.EditText">
<item name="android:importantForAutofill">noExcludeDescendants</item>
</style>

and in the values-v26/themes.xml file you can simply add to the default theme that you are using in your app the items editTextStyle and android:editTextStyle like following :

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
...
<item name="android:editTextStyle">@style/App_EditTextStyle</item>
<item name="editTextStyle">@style/App_EditTextStyle</item>
</style>

this way you can apply this changes for all your EditTexts without needing to change your layout files or Activities (and later on you can easily remove it when the bug is fixed).

In your EditText attributes add android:importantForAutofill="no" This should be a temporary fix and will only apply to api 26+

Create custom EditText style and set android:importantForAutofill to no.

<style name="EditTextStyleWithoutAutoFill" parent="Widget.AppCompat.EditText">
    <item name="android:importantForAutofill">no</item>
</style>

Then in your activity theme set this style for editTextStyle.

<item name="android:editTextStyle">@style/EditTextStyleWithoutAutoFill</item>

In my case, our app targets sdk version 21 but newer devices (26+) were still popping up the autocomplete. Pretty big problem if the app runs on devices that are shared between people. Using just android:importantForAutofill="no" did not work for me.

The only solution that I found to work in my case was:

<EditText
    android:importantForAutofill="no"
    tools:targetApi="o"
    android:autofillHints="AUTOFILL_HINT_SMS_OTP" ...

The reason I added android:autofillHints="AUTOFILL_HINT_SMS_OTP" was because if you long pressed on the EditText it would still bring up autofill. Basically I told the field's autofill that it is waiting for a text message that will never be sent. Bit of a hack, I know...

Note: you may have to add xmlns:tools="http://schemas.android.com/tools" to your schemas' if it is not there already.

With reference to Google issue tracker, it has been fixed.

This is fixed on Android 8.1

If any issue persists, please report at Google issue tracker they will re-open to examine.

Had the same problem with API 28+ and disable Autofill. For me the only solution was to disable long click for my views.

                <com.google.android.material.textfield.TextInputEditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:longClickable="false"
                    android:text="@={model.emailAdress}"/>

受限制的 HTML

  • 允许的HTML标签:<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。

相关推荐
  • Disabling android's chrome pull-down-to-refresh feature
    I've created a small HTML5 web application for my company. This application displays a list of items and everything works fine. The application is mainly used on android phones and Chrome as browser. Also, the site is saved on the home screen so Android manage the whole thing as an app (using a WebView I guess). Chrome Beta (and I think also the Android System WebView) has introduced a "pull down to refresh" feature (See this link for example). This is an handy feature but I was wondering if it can be disabled with some meta tag (or javascript stuff) because the refresh can be easily triggered
  • Disabling “Force Stop” Button in Android
    Okay, I'm pretty sure that this is not possible but a client had asked me to do so in one of our Android application we developed for her. What she had wanted is that if our application is running, and user navigate to: Settings > Manage Application > [Our Application] , the button for "Force Stop" is disabled. Is this possible? If it is possible, could someone point me out which way I should walk, or if it is not possible, how, using a valid argument based on facts, should I break the news to her. Update: She just sent me a screenshot that, in her opinion, validates her request that there's
  • 为横向模式的软键盘输入禁用全屏编辑视图?(Disabling the fullscreen editing view for soft keyboard input in landscape?)
    问题 在使用软键盘的Android设备上,我想防止在横向模式下出现全屏键盘编辑视图(如下所示)(即,我只希望看到软键盘本身以及背后的视图)。 我假设可以使用InputMethodService上的setExtractViewShown(false)方法来实现,但是我无法访问此方法的默认实例,也不想实现自定义输入法。 编辑添加:输入要进入的视图不是TextView (这是具有自定义InputConnection实现的View ),因此android:imeOptions="flagNoExtractUi"在这里不起作用。 回答1 我终于回答了我自己的问题: 可以在连接输入连接时禁用提取UI(即全屏编辑模式): @Override public InputConnection onCreateInputConnection(EditorInfo outAttrs) { outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI; // etc. } 回答2 为此,请导航至活动xml,然后在代码中粘贴android:imeOptions="flagNoExtractUi" 。 但是应该粘贴到哪里? 看一下示例活动xml的代码并看一下EditText: <?xml version="1.0" encoding="utf-8"?>
  • Disabling of EditText in Android
    In my application, I have an EditText that the user only has Read access not Write access. In code I set android:enabled="false". Although the background of EditText changed to dark, when I click on it the keyboard pops up and I can change the text. What should I set to disable EditText?
  • 关于以编程方式启用和禁用移动数据的最新更新[重复](Latest update on enabling and disabling mobile data programmatically [duplicate])
    问题 这个问题已经在这里有了答案: Android L(5.x)以编程方式打开/关闭“移动数据” (2个答案) 6个月前关闭。 尽管这是“重复的”,但当前答案已过时,并且在大多数情况下不再适用。 我认为最好在这里提供更新的资源,以节省人们的时间,就像我刚才所做的那样,研究这个问题。 我一直在四处搜寻,以查看有关能够在应用程序中启用和禁用移动数据的最新信息(如果无法使用wifi)。 这是我可以找到的最新内容之一: 您知道您不能再从小部件上禁用/启用棒棒糖上的数据吗? 有一个答案,我引用: 从来没有一个API。 开发人员正在使用一种变通办法,方法是通过Reflections调用该方法。 Google所做的一切就是关闭这个“漏洞利用”。 还有这个讨论: 替换setMobileDataEnabled()API 2015年2月。 这里有这些问题: 如何在Android上禁用移动数据 这个问题是在2010年提出的,而最新的答案在2014年12月更新了一个。 以编程方式在Android中启用/禁用数据连接 这是2012年接受的答案。 关于这个问题的最新消息是什么? 还能做吗? 回答1 由于他们添加了MODIFY_PHONE_STATE权限检查,因此无法在非root用户的手机上MODIFY_PHONE_STATE 。 此权限仅授予此处参考的系统或签名应用程序。
  • Disabling the context menu on long taps on Android
    I would like to disable the context menu that appears after a long tap (touch and hold) on images in my web application. I've seen posts with different ideas how to do it, but none of them seem to work for me. Is there a way to do this on Android via HTML/CSS/Javascript?
  • 如何以编程方式锁定/解锁屏幕?(How to Lock/Unlock screen programmatically?)
    问题 我正在做一个锁定屏幕晃动的应用程序。 现在,它处于锁定状态,如果屏幕关闭进入服务,则必须从那里转到广播接收器,而该服务必须打开屏幕。 以下是广播接收器: public class ScreenReceiver extends BroadcastReceiver { public static boolean wasScreenOn = true; @Override public void onReceive(Context context, Intent intent) { System.out.println("Entered Broadcaste Reciever"); if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { // DO WHATEVER YOU NEED TO DO HERE System.out.println("SCREEN_OFF"+wasScreenOn); wasScreenOn = false; Intent i = new Intent(context, UpdateService.class); i.putExtra("screen_state", wasScreenOn); context.startService(i); System.out.println(
  • EditText: Disable Paste/Replace menu pop-up on Text Selection Handler click event
    My goal is to have an EditText that has no fancy features, just the Text Selection Handler for moving the cursor more easily -- so no context menus or pop-ups. I've disabled the appearance of the text editing function actionbar (copy/Paste etc.) by consuming the ActionMode Callback event, as per this solution. The middle Middle Text Select Handle (see image below) still appears when text exists in the field and a click occurs within the text. Great! I want to keep this behaviour. What I DON'T want is the "PASTE" menu to appear when the Text Select Handle itself is clicked. I have also disabled
  • Android:无法添加窗口。 此窗口类型的权限被拒绝(Android: Unable to add window. Permission denied for this window type)
    问题 我工作的一个应用程序,我需要在未解锁手机,以显示与在锁屏(键盘保护)的一些信息的窗口。 我想我可以使用WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG做到这一点 但是,每次我的应用崩溃时,都会出现以下错误: android.view.WindowManager $ BadTokenException:无法添加窗口android.view.ViewRootImpl$W@40ec8528-此窗口类型的权限被拒绝 这些帖子(此处,此处和此处)都给出相同的答案。 在清单文件中添加以下权限。 android.permission.SYSTEM_ALERT_WINDOW 我已实施的解决方案,但仍然遇到相同的错误。 有什么想法我做错了吗? 这是清单文件中的权限: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.droidpilot.keyguardwindow" > <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="21" /> <uses-permission android
  • Broadcast Receiver Not Working After Device Reboot in Android
    I have already checked all the related questions and have not found any solution for this problem. So this is an absolutely new problem for me. What I Have I have an Android app which registers a few broadcast receivers in its manifest. This is what my manifest looks like. <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.app.myapp"> <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" /> <uses-permission android:name="android.permission.RECEIVE_BOOT
  • Android: How to make device run only one app?
    I have an customer project where I have to make single task android device. Customer isn't able to escape the application which my company have developed. Also customer isn't able to start any other application and our application is started when the device is booted. Overall all the customer is able to do with the device is run our application. Is there any other way to make this work than rooting the device, disabling all system buttons and making our application the launcher. I have something like 400 devices for this purpose so rooting all those would cost lot of time. I also read Google's
  • Screen overlay detected blocks Android permissions
    I've noticed a strange issue with my Android app on my new phone. SDK 23 permission popups like external storage are blocked by the attached alert below. I initially thought this was related to my phone, but it doesn't seem to affect any of my other installed apps. Is this issue perhaps related to having a debug version installed, or is it something wrong with my permission handling? I thought it could somehow be related to one of the ad platforms I'm using but I tried disabling them and it still showed up I've pasted the image saving function that is generate this permission request below. I
  • Android Studio 3.0 Manifest Error: unknown element <action> found
    NOTICE: Please do not post this "android.enableAapt2=false" as an answer. It is not a solution. It is just ignoring the real error which is not causing any problem on runtime. Solution was simple, just removed mistakenly placed action tag outside of an intent filter in the manifest file. Have an application which was building by Android Studio 2.3 fine. After updating Android Studio 3.0 Stable, started to having this error and unable to build my project. Here my manifest.xml <application android:name=".ApplicationClass" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android
  • 如何使Android设备振动? 不同的频率?(How to make an Android device vibrate? with different frequency?)
    问题 我写了一个Android应用程序。 现在,我想使设备在发生某种动作时振动。 我怎样才能做到这一点? 回答1 尝试: import android.os.Vibrator; ... Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // Vibrate for 500 milliseconds if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { v.vibrate(VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE)); } else { //deprecated in API 26 v.vibrate(500); } 笔记: 不要忘记在AndroidManifest.xml文件中包含权限: <uses-permission android:name="android.permission.VIBRATE"/> 回答2 授予振动许可 在开始实施任何振动代码之前,您必须授予应用程序振动的权限: <uses-permission android:name="android.permission.VIBRATE"/> 确保在AndroidManifest
  • Latest update on enabling and disabling mobile data programmatically [duplicate]
    This question already has answers here: Android L (5.x) Turn ON/OFF “Mobile Data” programmatically (2 answers) Closed 6 months ago. Although this is a "duplicate", the current answers are out of date and, mostly, no longer apply. I thought it would be good to provide an updated resource here, if possible, to save people time, as I have just done, researching this issue. I've been googling around to see the latest information on being able to enable and disable mobile data from within an app (if wifi is not available). This is one of the latest things I can find: Did you know you can no longer
  • 升级到Android 8.1后,startForeground失败(startForeground fail after upgrade to Android 8.1)
    问题 将手机升级到8.1 Developer Preview之后,我的后台服务不再正常启动。 在长期运行的服务中,我实现了startForeground方法来启动正在进行的通知,该通知在create时被调用。 @TargetApi(Build.VERSION_CODES.O) private fun startForeground() { // Safe call, handled by compat lib. val notificationBuilder = NotificationCompat.Builder(this, DEFAULT_CHANNEL_ID) val notification = notificationBuilder.setOngoing(true) .setSmallIcon(R.drawable.ic_launcher_foreground) .build() startForeground(101, notification) } 错误信息: 11-28 11:47:53.349 24704-24704/$PACKAGE_NAMEE/AndroidRuntime: FATAL EXCEPTION: main Process: $PACKAGE_NAME, PID: 24704 android.app.RemoteServiceException
  • Enable/disable data connection in android programmatically
    I want to enable/disable the data connection programmatically. I've used the following code: void enableInternet(boolean yes) { ConnectivityManager iMgr = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); Method iMthd = null; try { iMthd = ConnectivityManager.class.getDeclaredMethod("setMobileDataEnabled", boolean.class); } catch (Exception e) { } iMthd.setAccessible(false); if(yes) { try { iMthd.invoke(iMgr, true); Toast.makeText(getApplicationContext(), "Data connection Enabled", Toast.LENGTH_SHORT).show(); } catch (IllegalArgumentException e) { // TODO Auto-generated
  • Google Play Game Services - unable to sign in
    Right after yesterday's Google I/O keynote I've updated my Android SDK to integrate the game services into one of my apps. Things I've done so far: added and linked my app in the Dev Console (game services) included the OAuth client id into my app/manifest added BaseGameActivity and GameHelper to my project (from GitHub) added the google-play-services library to my project extended BaseGameActivity, added a com.google.android.gms.common.SignInButton I've also set up game meta data and, of course, some achievements. The dev console states that it is ready to release. To test the login flow and
  • Centos7部署MySQL 5.7.26二进制版本
    MySQL5.7部署可以分为rpm包部署、源码包部署、二进制包部署。 源码包部署:优点是灵活性较高,可以自定义编译参数,效率高,缺点是部署时间较长二进制包部署:优点是事先已经编译好,部署较快,可以自定义一部分参数,缺点是时间相比使用yum安装,还是较长rpm包部署:优点是部署速度快,缺点是定制性差一般没有特殊要求时,可以使用yum包部署下面开始使用二进制包部署MySQL5.7.26二进制包下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads在Select Operating System选项中选中”Linux Generic",在最下方的Linux - Generic (glibc 2.12) (x86, 64-bit), TAR项后方的download即可下载1.添加MySQL数据库运行的用户和用户组 groupadd -r mysql useradd -r -g mysql mysql 2.此次MySQL部署的目录为/application,将MySQL安装包解压到/application/mysql-5.7.26-linux-glibc2.12-x86_64目录,并为此目录创建软链接 ln -s /application/mysql-5.7.26-linux-glibc2.12-x86_64
  • Android 4.1:如何检查已禁用应用程序的通知?(Android 4.1: How to check notifications are disabled for the application?)
    问题 Android 4.1为用户提供了一个复选框,用于禁用特定应用程序的通知。 但是,作为开发人员,我们无法知道通知调用是否有效。 我确实需要检查当前应用程序是否禁用了通知,但是我在API中找不到任何设置。 有没有办法在代码中检查此设置? 回答1 你不可能100%不能。 在此Google I / O 2012视频中,系统要求新的通知的项目负责人声明您不能这样做。 编辑 2016年更新:如本Google I / O 2016视频所述,现在您可以检查它。 使用支持库中的NotificationManagerCompat.areNotificationsEnabled()来检查通知是否在API 19+上被阻止。 API 19以下的版本将返回true(启用通知)。 回答2 @blundell的回答是正确的,但是新版本中的更改很小。 NotificationManagerCompat.from(context).areNotificationsEnabled() 回答3 实际上,这很容易做到: /** * Created by desgraci on 5/7/15. */ public class NotificationsUtils { private static final String CHECK_OP_NO_THROW = "checkOpNoThrow"; private