Skip to content

Most visited

Recently visited

navigation

Autofill Framework

Android makes filling forms in apps easier thanks to the autofill framework introduced in Android 8.0 (API level 26). Android P provides improvements that autofill services can implement to further enhance the user experience.

Metrics

The FileEventHistory.Event class provides a new TYPE_CONTEXT_COMMITTED event that autofill services can use to get the following information:

For more information, see the TYPE_CONTEXT_COMMITTED constant.

Autofill services can also identify the datasets that the user selected by using the getDatasetIds() method of the SaveRequest class.

Input sanitization

The autofill framework provides sanitizer APIs that services can use to clean a field value before a save request is triggered. The sanitization is useful to avoid triggering save requests when an app formats a value that a service just filled out. For example, consider the following flow in an app that has a field for a credit card number:

  1. The autofill service has credit card datasets in which the credit card number is stored in the nnnnnnnnnnnnnnnn format (where n is a digit of the credit card number).
  2. The service fills out the field with the data mentioned in the previous step.
  3. The client app has formatting logic that adds a space every four digits of the credit card number. As a result, the field contains the data in the format nnnn nnnn nnnn nnnn.
  4. The formatting of the data triggers a save request and the save UI is shown for no reason.

Autofill services can avoid the extra save request by adding a sanitizer that removes the spaces added by the client app. For more information, see the addSanitizer() method of the SaveInfo.Builder class.

The autofill framework provides sanitizers for text and date values, see the TextValueSanitizer and DateValueSanitizer classes.

UI improvements

Dataset filtering

Datasets in Android P can include an optional regular expression that serves as a filter pattern for a field. The fill UI uses the filter pattern to decide which datasets to show. For more information, see Filtering.

An autofill service can set the dataset filter pattern for a field to null, which disables filtering for the dataset. This approach is recommended when setting the values of fields that contain sensitive data, such as passwords. For more information, see the setValue() method of the Dataset class.

Compatibility mode

The autofill framework provides a compatibility mode allowing services to work with apps that display their fields in a virtual structure and don't implement the APIs for such structures, such as browsers. For more information, see custom views with virtual structure.

The compatibility mode allows autofill services to use the accessibility virtual structure for autofill purposes. Compatibility mode uses the accessibility APIs to get the virtual structure, when needed.

Compatibility mode has the following limitations:

For more information, see compatibility mode.

Miscellaneous

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (April 2018 — Developer Survey)