0

I have a credit card EditText fields (full name, expiry date, creditcard number, cvv) that are all auto filled in android application.

The problem is the autofill prompt is showing up on every field. I just want the autofill to appear when user clicks on the creditcard field. If user clicks on cvv or expiry date for example, then there should be no prompt to autofill.

the key thing is that i still want all the fields to be autofill but I just don't want the prompt to show up on all of them.

what I have tried so far.

here is an example of the cvv field in which i tried to set

importantForAutoFill to "no"

but this makes the field get ignored completely. i just do not want the prompt to appear:

<EditText
                        android:id="@+id/et_cc_cvv"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:autofillHints="creditCardSecurityCode"
                        android:importantForAutofill="no"
                        android:drawableRight="@drawable/question_icon"
                        android:hint="@string/cvv"
                        android:imeOptions="actionDone"
                        android:inputType="number" />
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
j2emanue
  • 60,549
  • 65
  • 286
  • 456
  • Check this link https://stackoverflow.com/a/46082925/4938859. I have tried it and it is working fine. And for particular single EditText check answer of @Karoly – Piyush Malaviya Dec 20 '17 at 10:24
  • I do not think that there is an option for this. What autofill service(s) have you tested (as this behavior will vary by implementation)? – CommonsWare Dec 20 '17 at 11:26
  • @CommonsWare i have only used the default service that load with the Oreo emulator. nothing else. What do you suggest ? – j2emanue Dec 20 '17 at 17:00
  • @PiyushMalaviya i think your suggestion is more about turning off the autofill. thats not what i want. i just want to control when the system shows the prompt to autofill. What do you think ? – j2emanue Dec 20 '17 at 17:00
  • You could file a feature request, I suppose. – CommonsWare Dec 20 '17 at 17:00

1 Answers1

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


public void disableAutoFill() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        getWindow().getDecorView().setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS);
    }
}
Anjal Saneen
  • 3,109
  • 23
  • 38