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.
- The datasets that the user selected.
- The datasets that the user ignored.
- The fields in the selected datasets that the user changed.
- The fields that match the user data that the service sets for field classification purposes.
For more information, see the
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:
- The autofill service has credit card datasets in which the credit card number
is stored in the
nis a digit of the credit card number).
- The service fills out the field with the data mentioned in the previous step.
- 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
nnnn nnnn nnnn nnnn.
- 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
method of the
Autofill services can apply a series of updates to the save UI if a condition is satisfied. The series of updates are useful in cases where the screen has multiple fields (like username, password and address fields) but some are optional. For more information, see the
batchUpdate()method of the
ImageTransformationclass accepts a content description attribute, which makes it compatible with the accessibility features of the platform.
- The autofill framework provides a new
DateTransformationclass that services can use to display a string representation of a date in a child view of a
CustomDescriptionobject. This is useful to easily display dates in the save UI, for example, the expiration date of a credit card in
Autofill services can specify the view that commits the autofill context when tapped. In other words, apps can specify the view that serves as a submit button. This is useful in scenarios where the client app clears the views before the autofill context is automatically committed. For more information, see the
setTriggerId()method of the
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
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
method of the
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:
- A save request is only triggered when the service uses the
- The text value of the nodes might not be available in the
- When you point Chrome to a different URL, the new page might not be filled out. Restarting the browser might fix the issue.
urlBarResourceIdmetadata property only supports one value per app.
- Compatibility mode doesn't work with the version of Chrome bundled with Android P due to an accessibility issue. You must install Chrome Beta or Chrome Canary.
You must manually whitelist the apps that you want to support compatibility mode. For example to whitelist Chrome and Chrome Beta, use the following command:
adb shell settings put global autofill_compat_allowed_packages com.android.chrome:com.chrome.beta
For more information, see compatibility mode.
Autofill services can get the
android:idattribute in text views. The
android:textattribute of some views might not be meaningful to the service, for example, when the view is localized. Autofill services can use the
android:idattribute as additional input to determine the meaning of the data. For more information, see the
getTextIdEntry()method of the
getWebScheme()method returns the scheme part of a URL if the node represents an HTML document. Autofill services can use the web scheme in scenarios where a website is associated with an app. For more information see, Associate website and mobile app data.
AssistStructure.ViewNodeclass exposes the following information about the size of text fields:
Autofill services can provide an
onSuccess()method of a save request. The
IntentSenderis useful if the service needs the user to perform extra work before it can process the request. For more information, see the
onSuccess()method of the
Autofill services can disable autofill for specific client apps or activities. Disabling autofill is useful in cases where the service has blacklisted an app. Furthermore, disabling autofill can improve device performance because the autofill framework triggers fewer autofill requests. For more information, see the
disableAutofill()method and the