The following is the first few sections of a chapter from The Busy Coder's Guide to Android Development, plus headings for the remaining major sections, to give you an idea about the content of the chapter.
Many Web browsers, such as Chrome, offer “autofill”. The browser remembers things that you have typed into certain fields, like addresses, and offers to fill those back in when you go to fill in the same form again… or even a different form with similar fields.
Android 8.0 adds autofill capability to Android via the Autofill Framework. Values that users enter into your forms will be remembered and offered again when the user returns to your form, or to other forms that they encounter in other apps on the device. This all happens without any changes to your code… in theory. In practice, you may need some changes to your code.
However, Android itself does not store the form data, nor offer it as suggestions for autofilling in a form. Android is merely serving as a conduit between your app and a third-party autofill service. It is the service that is responsible for determining what could be autofilled in your form and saving prior entries. As with the Assist API, the user can choose an autofill service, and none ship by default with the O Developer Preview. In all likelihood, a Google-branded autofill implementation will be part of the production rollout of Android 8.0, but the user could choose other autofill apps… or perhaps none at all, for privacy reasons.
In this chapter, we will explore the AutoFill API, in terms of:
NOTE: O Developer Preview 2 renamed many of the Autofill Framework classes
and methods to make the
Autofill lowercase. So, for example,
AutofillService. Materials written based on O
Developer Preview 1 (blog posts, Stack Overflow answers, etc.) will
have a capital
Understanding this chapter requires that you have read the core chapters of this book.
There are commonalities between autofill and the Assist API, and so this chapter will refer back to that one from time to time.
Android 8.0 provides a framework for apps with a UI to participate in autofill, by denoting roles that some of those widgets have (e.g., “this is the field for the username”). However, Android itself does not save any user input for later use with autofill, nor does Android itself decide what values are candidates for autofill. Instead, Android delegates that work to a separate autofill service. This works akin to how accessibility services and input method editors work:
Hence, with autofill, there are three pieces: the app with the UI, Android itself, and the autofill service:
Figure 703: Pieces of Autofill
onSuccess() are part of the API for autofill
The preview of this section may contain nuts.
The preview of this section was eaten by a grue.
The preview of this section is unavailable right now, but if you leave your name and number at the sound of the tone, it might get back to you (BEEEEEEEEEEEEP!).
The preview of this section was lost due to a rupture in the space-time continuum.
The preview of this section was abducted by space aliens.
The preview of this section was traded for a bag of magic beans.
The preview of this section was the victim of a MITM ('Martian in the middle') attack.