Skip to content

Most visited

Recently visited

navigation

Test your app with autofill

Some apps, such as password managers, can fill out the views in other apps with data previously provided by the user. These apps that fill out other apps are called autofill services. Most apps work with autofill services without any changes. However, you can optimize your app to ensure it works as best as it can with autofill services. After you optimize your app, you should test it to make sure it works as intended with autofill services.

To better understand how to test your app with autofill services, you should understand how autofill services and clients fit in the Autofill Framework. The following are the high-level components of the framework:

You should use an emulator or a physical device running Android 8.0 (API level 26) or higher to test your app. For more information about how to create an emulator, see Create and Manage Virtual Devices.

Install an autofill service

Before you can test your app with autofill, you need to install another app that provides autofill services. You could use third-party app for this purpose, but it's easier to use a sample autofill service to test your app. If you use a sample app you don't need to sign up for any third-party services.

You can use the Android Autofill Framework sample to test your app with autofill services. The sample app provides an autofill service and client Activities that you can use to test the workflow before using it with your app. The sample app is referenced throughout this article.

After you have installed the app, you should enable the autofill service in the system settings. You can enable the service in Settings > System > Languages & input > Advanced > Input assistance > Autofill service.

Analyze data requirements

To test your app with the autofill service, the service needs to have data that it can use to fill out your app. The service also needs to understand what type of data is expected in the views of your app. For example, if your app has a view that expects a username, the service should have a dataset that contains a username and some mechanism to know that the view expects such data.

You should let the service know what type of data is expected in your views by setting the android:autofillHints attribute. Some services use sophisticated heuristics to determine the type of data, but others, such as the sample app, rely on the developer to provide this information. Your app works better with autofill services if you set the android:autofillHints attribute in the views that are relevant for autofill.

Run your test

After you have analyzed the data requirements, you can run your test, which includes saving test data in the autofill service and triggering autofill in your app.

Save data in the service

The following steps show how to save data in the autofill service that is currently active:

  1. Open an app that has a view that expects the type of data that you want to use in your test. The sample app provides UI with views that expect several types of data, such as credit card number and username.
  2. Tap the view that holds the type of data you need and type a value in it. You usually have to submit the form before the service attempts to save the data. For example, a login form requires you to provide username and password and tap a sign in or submit button.
  3. Android System displays a dialog that asks for your permission to save the data. The dialog shows the name of the service that is currently active. Verify that this is the service that you want to use in your test.
  4. Tap Save.

If Android doesn't display the permission dialog, or if the service is not the one you want to use in your test, then check that the service is currently active in system settings.

Trigger autofill in your app

The following steps show how to trigger autofill in your app:

  1. Open your app and go to the activity that has the views you want to test.
  2. Tap the view that should be filled out.
  3. Android System should display the autofill UI, which contains the datasets that can fill the view, as shown in the screenshot below.
  4. Tap the dataset that contains the data that you want to use. The view should display the data previously stored in the service.

Autofill UI

Autofill UI displaying available datasets.

If Android doesn't display the autofill UI, you can try the following troubleshooting options:

For more information on how to optimize your app for autofill, see Autofill Framework.

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!

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.
(Sep 2017 survey)