UserData.Builder


public static final class UserData.Builder
extends Object

java.lang.Object
   ↳ android.service.autofill.UserData.Builder


A builder for UserData objects.

Summary

Public constructors

Builder(String id, String value, String categoryId)

Creates a new builder for the user data used for field classification.

Public methods

UserData.Builder add(String value, String categoryId)

Adds a new value for user data.

UserData build()

Creates a new UserData instance.

UserData.Builder setFieldClassificationAlgorithm(String name, Bundle args)

Sets the default algorithm used for field classification.

UserData.Builder setFieldClassificationAlgorithmForCategory(String categoryId, String name, Bundle args)

Sets the algorithm used for field classification for the specified category.

Inherited methods

Public constructors

Builder

Added in API level 28
public Builder (String id, 
                String value, 
                String categoryId)

Creates a new builder for the user data used for field classification.

The user data must contain at least one pair of value -> categoryId, and more pairs can be added through the add(java.lang.String, java.lang.String) method. For example:

 new UserData.Builder("v1", "Bart Simpson", "name")
   .add("bart.simpson@example.com", "email")
   .add("el_barto@example.com", "email")
   .build();
 

Parameters
id String: id used to identify the whole UserData object. This id is also returned by AutofillManager.getUserDataId(), which can be used to check if the UserData is up-to-date without fetching the whole object (through AutofillManager.getUserData()). This value cannot be null.

value String: value of the user data. This value cannot be null.

categoryId String: autofill field category. This value cannot be null.

Throws
IllegalArgumentException if any of the following occurs:

Public methods

add

Added in API level 28
public UserData.Builder add (String value, 
                String categoryId)

Adds a new value for user data.

Parameters
value String: value of the user data. This value cannot be null.

categoryId String: string used to identify the category the value is associated with. This value cannot be null.

Returns
UserData.Builder This value cannot be null.

Throws
IllegalStateException if:
IllegalArgumentException if any of the following occurs:

build

Added in API level 28
public UserData build ()

Creates a new UserData instance.

You should not interact with this builder once this method is called.

Returns
UserData The built dataset. This value cannot be null.

Throws
IllegalStateException if build() was already called.

setFieldClassificationAlgorithm

Added in API level 28
public UserData.Builder setFieldClassificationAlgorithm (String name, 
                Bundle args)

Sets the default algorithm used for field classification.

The currently available algorithms can be retrieve through AutofillManager.getAvailableFieldClassificationAlgorithms().

If not set, the default algorithm is used instead.

Parameters
name String: name of the algorithm or null to used default.

args Bundle: optional arguments to the algorithm. This value may be null.

Returns
UserData.Builder this builder This value cannot be null.

setFieldClassificationAlgorithmForCategory

Added in API level 29
public UserData.Builder setFieldClassificationAlgorithmForCategory (String categoryId, 
                String name, 
                Bundle args)

Sets the algorithm used for field classification for the specified category.

The currently available algorithms can be retrieved through AutofillManager.getAvailableFieldClassificationAlgorithms().

If not set, the default algorithm is used instead.

Parameters
categoryId String: autofill field category. This value cannot be null.

name String: name of the algorithm or null to used default.

args Bundle: optional arguments to the algorithm. This value may be null.

Returns
UserData.Builder this builder This value cannot be null.