Skip to content

Most visited

Recently visited

navigation

FillResponse

public final class FillResponse
extends Object implements Parcelable

java.lang.Object
   ↳ android.service.autofill.FillResponse


Response for a onFillRequest(android.app.assist.AssistStructure, Bundle, android.os.CancellationSignal, FillCallback).

The response typically contains one or more Datasets, each representing a set of fields that can be auto-filled together, and the Android system displays a dataset picker UI affordance that the user must use before the Activity is filled with the dataset.

For example, for a login page with username/password where the user only has one account in the response could be:

  new FillResponse.Builder()
      .add(new Dataset.Builder(createPresentation())
          .setTextFieldValue(id1, "homer")
          .setTextFieldValue(id2, "D'OH!")
          .build())
      .build();
 

If the user had 2 accounts, each with its own user-provided names, the response could be:

  new FillResponse.Builder()
      .add(new Dataset.Builder(createFirstPresentation())
          .setTextFieldValue(id1, "homer")
          .setTextFieldValue(id2, "D'OH!")
          .build())
      .add(new Dataset.Builder(createSecondPresentation())
          .setTextFieldValue(id1, "elbarto")
          .setTextFieldValue(id2, "cowabonga")
          .build())
      .build();
 

If the user does not have any data associated with this Activity but the service wants to offer the user the option to save the data that was entered, then the service could populate the response with savableIds instead of Datasets:

  new FillResponse.Builder()
      .addSavableFields(id1, id2)
      .build();
 

Similarly, there might be cases where the user data on the service is enough to populate some fields but not all, and the service would still be interested on saving the other fields. In this scenario, the service could populate the response with both Datasets and savableIds:

   new FillResponse.Builder()
       .add(new Dataset.Builder(createPresentation())
          .setTextFieldValue(id1, "Homer")                  // first name
          .setTextFieldValue(id2, "Simpson")                // last name
          .setTextFieldValue(id3, "742 Evergreen Terrace")  // street
          .setTextFieldValue(id4, "Springfield")            // city
          .build())
       .addSavableFields(id5, id6) // state and zipcode
       .build();

 

Notice that the ids that are part of a dataset (ids 1 to 4, in this example) are automatically added to the savableIds list.

If the service has multiple Datasets for different sections of the activity, for example, a user section for which there are two datasets followed by an address section for which there are two datasets for each user user, then it should "partition" the activity in sections and populate the response with just a subset of the data that would fulfill the first section (the name in our example); then once the user fills the first section and taps a field from the next section (the address in our example), the Android system would issue another request for that section, and so on. Note that if the user chooses to populate the first section with a service provided dataset, the subsequent request would contain the populated values so you don't try to provide suggestions for the first section but ony for the second one based on the context of what was already filled. For example, the first response could be:

  new FillResponse.Builder()
      .add(new Dataset.Builder(createFirstPresentation())
          .setTextFieldValue(id1, "Homer")
          .setTextFieldValue(id2, "Simpson")
          .build())
      .add(new Dataset.Builder(createSecondPresentation())
          .setTextFieldValue(id1, "Bart")
          .setTextFieldValue(id2, "Simpson")
          .build())
      .build();
 

Then after the user picks the second dataset and taps the street field to trigger another auto-fill request, the second response could be:

  new FillResponse.Builder()
      .add(new Dataset.Builder(createThirdPresentation())
          .setTextFieldValue(id3, "742 Evergreen Terrace")
          .setTextFieldValue(id4, "Springfield")
          .build())
      .add(new Dataset.Builder(createFourthPresentation())
          .setTextFieldValue(id3, "Springfield Power Plant")
          .setTextFieldValue(id4, "Springfield")
          .build())
      .build();
 

The service could require user authentication at the FillResponse or the Dataset level, prior to auto-filling an activity - see #setAuthentication(IntentSender) and setAuthentication(IntentSender). It is recommended that you encrypt only the sensitive data but leave the labels unencrypted which would allow you to provide a dataset presentation views with labels and if the user chooses one of them challenge the user to authenticate. For example, if the user has a home and a work address the Home and Work labels could be stored unencrypted as they don't have any sensitive data while the address data is in an encrypted storage. If the user chooses Home, then the platform will start your authentication flow. If you encrypt all data and require auth at the response level the user will have to interact with the fill UI to trigger a request for the datasets (as they don't see the presentation views for the possible options) which will start your auth flow and after successfully authenticating the user will be presented with the Home and Work options to pick one. Hence, you have flexibility how to implement your auth while storing labels non-encrypted and data encrypted provides a better user experience.

Summary

Nested classes

class FillResponse.Builder

Builder for FillResponse objects. 

Inherited constants

From interface android.os.Parcelable

Fields

public static final Creator<FillResponse> CREATOR

Public methods

int describeContents()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.

String toString()

Returns a string representation of the object.

void writeToParcel(Parcel parcel, int flags)

Flatten this object in to a Parcel.

Inherited methods

From class java.lang.Object
From interface android.os.Parcelable

Fields

Public methods

describeContents

int describeContents ()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. For example, if the object will include a file descriptor in the output of writeToParcel(Parcel, int), the return value of this method must include the CONTENTS_FILE_DESCRIPTOR bit.

Returns
int a bitmask indicating the set of special object types marshaled by this Parcelable object instance.

toString

String toString ()

Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Returns
String a string representation of the object.

writeToParcel

void writeToParcel (Parcel parcel, 
                int flags)

Flatten this object in to a Parcel.

Parameters
parcel Parcel: The Parcel in which the object should be written.
flags int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

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 one-minute survey?
Help us improve Android tools and documentation.