Is it possible to use the new Android Oreo autofill feature for a birthday too? And is there a way to distinguish between firstname & lastname? I only saw the AUTOFILL_HINT_NAME in the API docs.
Is it possible to use the new Android Oreo autofill feature for a birthday too? And is there a way to distinguish between firstname & lastname? I only saw the AUTOFILL_HINT_NAME in the API docs.
After wasting a day at work trying to add an autofillHints for the first name, because obviously family-name works for google autofill service :@ but nothing worked for the first name. so I checked Facebook app and Flixbus and guess what both of them can autofill the first name, so desperate I am, I tried cc-given-name and it freaking worked!!!!! even that the google account name on the phone was the company's and it didn't have any credit cards entered for it before.
The sad part is that nobody from the Android team bothered to mention the family-name hint or the fact that cc-given-name actually is there regardless if you ever filled a credit card info using your account before.
So For me, I just used EditText only without any labels or so, but I had to add android:hint="First name" and android:hint="Last name" for the auto complete to show, so without the hint it didn't work.
So it was like this: (removed ids, layout_width/height and orientation for simplicity)
<LinearLayout android:orientation="horizontal">
<EditText
android:autofillHints="cc-given-name"
android:hint="First name"/>
<EditText
android:autofillHints="family-name"
android:hint="Last name"/>
</LinearLayout>
Many more autofill hint values are now documented
https://developer.android.com/reference/androidx/autofill/HintConstants
I used these values for first and last name,and they worked well
".AUTOFILL_HINT_PERSON_NAME_FAMILY"".AUTOFILL_HINT_PERSON_NAME_GIVEN"Attention: there is a "." at the beginning of both of those strings.
I found the autofill UI to be slightly confusing because the popup displays the full name when filling out the first name field (see screenshot below). But when the user clicks on their fullname, both first and last name fields are filled out at once, which is cool!
Those attributes View.AUTOFILL_HINT_* are not exaustive, but instead suggestions. In android:autofillHints you can set any string that you like and even multiples ones separated by comma, from the docs:
Describes the content of a view so that a autofill service can fill in the appropriate data. Multiple hints can be combined in a comma separated list or an array of strings to mean e.g. emailAddress or postalAddress.
The autofill services receives those hints and according to their algorithm implementation returns a FillResponse data set with the possible data to fill in.
The service can even look in the node for views that contains labels like "First name" to detemine that your EditText wants first name instead of full name. You can put 'first-name' at your autofillHint, but it will only works if the user has an autofill service that have the first name data and his algorithm is smart enough to match it.
In short, there is no guarantee that autofill will work for a particular user, but there is some procedures that will increase the chance:
autofillHint you think can help, separated by commas. Rembember to use constants that other systems use or industry standards, for instance HTML standard uses given-name for first name. If Google autofill starts to support first name and last name that will be a likely candidate to their match algorithm, so an android:autofillHint="first-name,given-name,display-name" will have high probability of matching.android:importantForAutofill="yes" if you are using some TextView for label and try to put in the same view node.EditText, AutocompleteTextView, and other views already optmized for autofill.Check this autofill optmize Android guide for more tips.
Check the list of HTML standard autofill tags:
Is it possible to use the new Android Oreo autofill feature for a birthday too?
No. Hopefully, few people are repeatedly entering their birthday into the same app.
And is there a way to distinguish between firstname & lastname?
No.
Android's autofill supports a small subset of HTML5's autocomplete detail tokens.