16: Skipping password saving since the user is likely prompted with Android Autofill
Asked Answered
U

2

6

I am integrating google smart lock in my android application but in some devices i am getting this error when trying to save credentials to google. I am using following code to save credentials -

 Credential credential = new Credential.Builder(email)
                                       .setPassword(password)
                                       .build();
 saveCredentials(credential);

After search on google for this solution found that need to disable auto-fill feature in application to save the password.

Try 1 - Put the following code in activity for commit autofillmager in specific activity and disable autofill. But it is not working.

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

    AutofillManager autofillManager = getSystemService(AutofillManager.class);
    autofillManager.commit();

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

Try 2 - Put following in properties in EditText

 android:longClickable="false"

longClickable should stop autofill but it is not working.

 android:importantForAutofill="no"

Also try with importantForAutoFill but it is also not working.

Universalize answered 1/3, 2021 at 12:27 Comment(1)
[2023] were you able to find an answer for this issue..i have searched again and again but the findings does not fix this issue..Marjorie
M
0

Finally i was able to find a work around.This error appears because system autofill is trying to overtake your google autofill implementation..

So first we have to disable Android OS from trying to autofill the input fields & disable the autofill for our app.

To disable the autofill i have done 2 things..

I have tried disabling the system autofill through following xml attributes, which didn't work at all.

android:importantForAutofill="no"

Which does not work at all..Then i found the following Answer.Which suggest to implement a custom EditText (or whatever input type) and disable autofill attempt from the source.implement your own version of EdiText as follows.

public class EditTextWithNoAutoFill extends androidx.appcompat.widget.AppCompatEditText {

    public EditTextWithNoAutoFill(@NonNull Context context) {
        super(context);
    }

    public EditTextWithNoAutoFill(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public EditTextWithNoAutoFill(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

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

    @Override
    public int getImportantForAutofill() {
        return IMPORTANT_FOR_AUTOFILL_NO;
    }
}

}

Fixe lies in these two method implementations 'getImportantForAutofill()' & 'getAutofillType()'

Then additionally i applied this too..

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            getWindow().getDecorView().setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS);
        }

After applying these two changes and running it , did not instantly solved the issue for me..i had to restart the running device/Clean build cache/Restart android studio (Not sure which option triggered the fix)

After the above changes it was all working fine.

For more reference regarding disabling OS 'Autofill' i am leaving this reference to the original answer

https://mcmap.net/q/205699/-disabling-android-o-auto-fill-service-for-an-application

Marjorie answered 16/5, 2023 at 3:14 Comment(0)
C
-1

I removed all the code for manual saving and just added android:autofillHints="username" for login field and android:autofillHints="password" for password field in the sign in form. Password saving dialog appears all the same, thanks to the Android's Autofill service.

Coincide answered 2/9, 2021 at 10:25 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.