Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/android/service/autofill/UserData.Builder#pubctors) \| [Methods](https://developer.android.com/reference/android/service/autofill/UserData.Builder#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/service/autofill/UserData.Builder#inhmethods)

# UserData.Builder

*** ** * ** ***

` public static final class UserData.Builder `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.service.autofill.UserData.Builder |

<br />

*** ** * ** ***

A builder for `https://developer.android.com/reference/android/service/autofill/UserData` objects.

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/service/autofill/UserData.Builder#Builder(java.lang.String,%20java.lang.String,%20java.lang.String)(https://developer.android.com/reference/java/lang/String id, https://developer.android.com/reference/java/lang/String value, https://developer.android.com/reference/java/lang/String categoryId) ` Creates a new builder for the user data used for [field classification](https://developer.android.com/reference/android/service/autofill/UserData.Builder#FieldClassification). |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/android/service/autofill/UserData.Builder` | ` https://developer.android.com/reference/android/service/autofill/UserData.Builder#add(java.lang.String,%20java.lang.String)(https://developer.android.com/reference/java/lang/String value, https://developer.android.com/reference/java/lang/String categoryId) ` Adds a new value for user data. |
| ` https://developer.android.com/reference/android/service/autofill/UserData` | ` https://developer.android.com/reference/android/service/autofill/UserData.Builder#build()() ` Creates a new `https://developer.android.com/reference/android/service/autofill/UserData` instance. |
| ` https://developer.android.com/reference/android/service/autofill/UserData.Builder` | ` https://developer.android.com/reference/android/service/autofill/UserData.Builder#setFieldClassificationAlgorithm(java.lang.String,%20android.os.Bundle)(https://developer.android.com/reference/java/lang/String name, https://developer.android.com/reference/android/os/Bundle args) ` Sets the default algorithm used for [field classification](https://developer.android.com/reference/android/service/autofill/UserData.Builder#FieldClassification). |
| ` https://developer.android.com/reference/android/service/autofill/UserData.Builder` | ` https://developer.android.com/reference/android/service/autofill/UserData.Builder#setFieldClassificationAlgorithmForCategory(java.lang.String,%20java.lang.String,%20android.os.Bundle)(https://developer.android.com/reference/java/lang/String categoryId, https://developer.android.com/reference/java/lang/String name, https://developer.android.com/reference/android/os/Bundle args) ` Sets the algorithm used for [field classification](https://developer.android.com/reference/android/service/autofill/UserData.Builder#FieldClassification) for the specified category. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Public constructors

### Builder

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Builder (String id, 
                String value, 
                String categoryId)
```

Creates a new builder for the user data used for [field classification](https://developer.android.com/reference/android/service/autofill/UserData.Builder#FieldClassification).

The user data must contain at least one pair of `value` -\> `categoryId`, and more pairs can be added through the `https://developer.android.com/reference/android/service/autofill/UserData.Builder#add(java.lang.String,%20java.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();
```

<br />

<br />

| Parameters ||
|---|---|
| `id` | `String`: id used to identify the whole `https://developer.android.com/reference/android/service/autofill/UserData` object. This id is also returned by `https://developer.android.com/reference/android/view/autofill/AutofillManager#getUserDataId()`, which can be used to check if the `https://developer.android.com/reference/android/service/autofill/UserData` is up-to-date without fetching the whole object (through `https://developer.android.com/reference/android/view/autofill/AutofillManager#getUserData()`). This value cannot be `null`. <br /> |
| `value` | `String`: value of the user data. This value cannot be `null`. <br /> |
| `categoryId` | `String`: autofill field category. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if any of the following occurs: - `id` is empty - `categoryId` is empty - `value` is empty - the length of `value` is lower than `https://developer.android.com/reference/android/service/autofill/UserData#getMinValueLength()` - the length of `value` is higher than `https://developer.android.com/reference/android/service/autofill/UserData#getMaxValueLength()` |

## Public methods

### add

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public UserData.Builder add (String value, 
                String categoryId)
```

Adds a new value for user data.

<br />

| Parameters ||
|---|---|
| `value` | `String`: value of the user data. This value cannot be `null`. <br /> |
| `categoryId` | `String`: string used to identify the category the value is associated with. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/service/autofill/UserData.Builder` | This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if any of the following occurs: - `id` is empty - `categoryId` is empty - `value` is empty - the length of `value` is lower than `https://developer.android.com/reference/android/service/autofill/UserData#getMinValueLength()` - the length of `value` is higher than `https://developer.android.com/reference/android/service/autofill/UserData#getMaxValueLength()` |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if: - `https://developer.android.com/reference/android/service/autofill/UserData.Builder#build()` already called - the `value` has already been added (**Note:** this restriction was lifted on Android `https://developer.android.com/reference/android/os/Build.VERSION_CODES#Q` and later) - the number of unique `categoryId` values added so far is more than `https://developer.android.com/reference/android/service/autofill/UserData#getMaxCategoryCount()` - the number of `values` added so far is is more than `https://developer.android.com/reference/android/service/autofill/UserData#getMaxUserDataSize()` |

### build

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public UserData build ()
```

Creates a new `https://developer.android.com/reference/android/service/autofill/UserData` instance.

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

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/service/autofill/UserData` | The built dataset. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if `https://developer.android.com/reference/android/service/autofill/UserData.Builder#build()` was already called. |

### setFieldClassificationAlgorithm

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public UserData.Builder setFieldClassificationAlgorithm (String name, 
                Bundle args)
```

Sets the default algorithm used for [field classification](https://developer.android.com/reference/android/service/autofill/UserData.Builder#FieldClassification).

The currently available algorithms can be retrieve through `https://developer.android.com/reference/android/view/autofill/AutofillManager#getAvailableFieldClassificationAlgorithms()`.

If not set, the `https://developer.android.com/reference/android/view/autofill/AutofillManager#getDefaultFieldClassificationAlgorithm()` is used instead.

<br />

| Parameters ||
|---|---|
| `name` | `String`: name of the algorithm or `null` to used default. <br /> |
| `args` | `Bundle`: optional arguments to the algorithm. This value may be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/service/autofill/UserData.Builder` | this builder. This value cannot be `null`. <br /> |

### setFieldClassificationAlgorithmForCategory

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

Sets the algorithm used for [field classification](https://developer.android.com/reference/android/service/autofill/UserData.Builder#FieldClassification) for the specified category.

The currently available algorithms can be retrieved through `https://developer.android.com/reference/android/view/autofill/AutofillManager#getAvailableFieldClassificationAlgorithms()`.

If not set, the `https://developer.android.com/reference/android/view/autofill/AutofillManager#getDefaultFieldClassificationAlgorithm()` is used instead.

<br />

| Parameters ||
|---|---|
| `categoryId` | `String`: autofill field category. This value cannot be `null`. <br /> |
| `name` | `String`: name of the algorithm or `null` to used default. <br /> |
| `args` | `Bundle`: optional arguments to the algorithm. This value may be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/service/autofill/UserData.Builder` | this builder. This value cannot be `null`. <br /> |