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

# SaveInfo.Builder

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/service/autofill/SaveInfo.Builder "View this page in Kotlin") \|Java


`
public
static
final

class
SaveInfo.Builder
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

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

<br />

*** ** * ** ***

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

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder#Builder(int)(int type) ` Creates a new builder when no id is required. |
| ` https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder#Builder(int,%20android.view.autofill.AutofillId[])(int type, https://developer.android.com/reference/android/view/autofill/AutofillId requiredIds) ` Creates a new builder. |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder` | ` https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder#addSanitizer(android.service.autofill.Sanitizer,%20android.view.autofill.AutofillId[])(https://developer.android.com/reference/android/service/autofill/Sanitizer sanitizer, https://developer.android.com/reference/android/view/autofill/AutofillId ids) ` Adds a sanitizer for one or more field. |
| ` https://developer.android.com/reference/android/service/autofill/SaveInfo` | ` https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder#build()() ` Builds a new `https://developer.android.com/reference/android/service/autofill/SaveInfo` instance. |
| ` https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder` | ` https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder#setCustomDescription(android.service.autofill.CustomDescription)(https://developer.android.com/reference/android/service/autofill/CustomDescription customDescription) ` Sets a custom description to be shown in the UI when the user is asked to save. |
| ` https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder` | ` https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder#setDescription(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence description) ` Sets an optional description to be shown in the UI when the user is asked to save. |
| ` https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder` | ` https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder#setFlags(int)(int flags) ` Sets flags changing the save behavior. |
| ` https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder` | ` https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder#setNegativeAction(int,%20android.content.IntentSender)(int style, https://developer.android.com/reference/android/content/IntentSender listener) ` Sets the style and listener for the negative save action. |
| ` https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder` | ` https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder#setOptionalIds(android.view.autofill.AutofillId[])(https://developer.android.com/reference/android/view/autofill/AutofillId ids) ` Sets the ids of additional, optional views the service would be interested to save. |
| ` https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder` | ` https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder#setPositiveAction(int)(int style) ` Sets the style for the positive save action. |
| ` https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder` | ` https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder#setTriggerId(android.view.autofill.AutofillId)(https://developer.android.com/reference/android/view/autofill/AutofillId id) ` Explicitly defines the view that should commit the autofill context when clicked. |
| ` https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder` | ` https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder#setValidator(android.service.autofill.Validator)(https://developer.android.com/reference/android/service/autofill/Validator validator) ` Sets an object used to validate the user input - if the input is not valid, the autofill save UI is not shown. |

| ### 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 27](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Builder (int type)
```

Creates a new builder when no id is required.

When using this builder, caller must call `https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder#setOptionalIds(android.view.autofill.AutofillId[])` before
calling `https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder#build()`.

<br />

| Parameters ||
|---|---|
| `type` | `int`: the type of information the associated `https://developer.android.com/reference/android/service/autofill/FillResponse` represents. It can be any combination of `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_GENERIC`, `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_PASSWORD`, `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_ADDRESS`, `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_CREDIT_CARD`, `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_DEBIT_CARD`, `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_PAYMENT_CARD`, `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_GENERIC_CARD`, `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_USERNAME`, or `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_EMAIL_ADDRESS`. See `https://developer.android.com/reference/android/service/autofill/SaveInfo` for more info. Value is either `0` or a combination of the following: - `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_GENERIC` - `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_PASSWORD` - `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_ADDRESS` - `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_CREDIT_CARD` - `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_USERNAME` - `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_EMAIL_ADDRESS` - `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_DEBIT_CARD` - `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_PAYMENT_CARD` - `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_GENERIC_CARD` |

### Builder

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

```
public Builder (int type, 
                AutofillId[] requiredIds)
```

Creates a new builder.

<br />

| Parameters ||
|---|---|
| `type` | `int`: the type of information the associated `https://developer.android.com/reference/android/service/autofill/FillResponse` represents. It can be any combination of `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_GENERIC`, `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_PASSWORD`, `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_ADDRESS`, `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_CREDIT_CARD`, `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_DEBIT_CARD`, `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_PAYMENT_CARD`, `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_GENERIC_CARD`, `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_USERNAME`, or `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_EMAIL_ADDRESS`. Value is either `0` or a combination of the following: - `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_GENERIC` - `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_PASSWORD` - `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_ADDRESS` - `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_CREDIT_CARD` - `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_USERNAME` - `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_EMAIL_ADDRESS` - `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_DEBIT_CARD` - `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_PAYMENT_CARD` - `https://developer.android.com/reference/android/service/autofill/SaveInfo#SAVE_DATA_TYPE_GENERIC_CARD` |
| `requiredIds` | `AutofillId`: ids of all required views that will trigger a save request. See `https://developer.android.com/reference/android/service/autofill/SaveInfo` for more info. This value cannot be `null`. |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `requiredIds` is `null` or empty, or if it contains any `null` entry. |

## Public methods

### addSanitizer

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

```
public SaveInfo.Builder addSanitizer (Sanitizer sanitizer, 
                AutofillId... ids)
```

Adds a sanitizer for one or more field.

When a sanitizer is set for a field, the `https://developer.android.com/reference/android/view/autofill/AutofillValue` is sent to the
sanitizer before a save request is [triggered](https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder#TriggeringSaveRequest).

Typically used to avoid displaying the save UI for values that are autofilled but
reformattedby the app. For example, to remove spaces between every 4 digits of a
credit card number:

```text
 builder.addSanitizer(new TextValueSanitizer(
     Pattern.compile("^(\\d{4})\\s?(\\d{4})\\s?(\\d{4})\\s?(\\d{4})$", "$1$2$3$4")),
     ccNumberId);
 
```

The same sanitizer can be reused to sanitize multiple fields. For example, to trim
both the username and password fields:

```scdoc
 builder.addSanitizer(
     new TextValueSanitizer(Pattern.compile("^\\s*(.*)\\s*$"), "$1"),
         usernameId, passwordId);
 
```

The sanitizer can also be used as an alternative for a
`https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder#setValidator(android.service.autofill.Validator)`. If any of the `ids` is a
`https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder#Builder(int,%20android.view.autofill.AutofillId[])` and the `sanitizer` fails
because of it, then the save UI is not shown.

<br />

| Parameters ||
|---|---|
| `sanitizer` | `Sanitizer`: an implementation provided by the Android System. This value cannot be `null`. <br /> |
| `ids` | `AutofillId`: id of fields whose value will be sanitized. This value cannot be `null`. <br /> |

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

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if a sanitizer for any of the `ids` has already been added or if `ids` is empty. |

### build

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

```
public SaveInfo build ()
```

Builds a new `https://developer.android.com/reference/android/service/autofill/SaveInfo` instance.

If no `https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder#Builder(int,%20android.view.autofill.AutofillId[])`,
or `https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder#setOptionalIds(android.view.autofill.AutofillId[])`, or `https://developer.android.com/reference/android/service/autofill/SaveInfo#FLAG_DELAY_SAVE`
were set, Save Dialog will only be triggered if platform detection is enabled, which
is indicated when `https://developer.android.com/reference/android/service/autofill/FillRequest#getHints()` is not empty.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/service/autofill/SaveInfo` | <br /> |

### setCustomDescription

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

```
public SaveInfo.Builder setCustomDescription (CustomDescription customDescription)
```

Sets a custom description to be shown in the UI when the user is asked to save.

Typically used when the service must show more info about the object being saved,
like a credit card logo, masked number, and expiration date.

<br />

| Parameters ||
|---|---|
| `customDescription` | `CustomDescription`: the custom description. This value cannot be `null`. <br /> |

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

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if this call was made after calling `https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder#setDescription(java.lang.CharSequence)`. |

### setDescription

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

```
public SaveInfo.Builder setDescription (CharSequence description)
```

Sets an optional description to be shown in the UI when the user is asked to save.

Typically, it describes how the data will be stored by the service, so it can help
users to decide whether they can trust the service to save their data.

<br />

| Parameters ||
|---|---|
| `description` | `CharSequence`: a succint description. This value may be `null`. <br /> |

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

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if this call was made after calling `https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder#setCustomDescription(android.service.autofill.CustomDescription)`. |

### setFlags

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

```
public SaveInfo.Builder setFlags (int flags)
```

Sets flags changing the save behavior.

<br />

| Parameters ||
|---|---|
| `flags` | `int`: `https://developer.android.com/reference/android/service/autofill/SaveInfo#FLAG_SAVE_ON_ALL_VIEWS_INVISIBLE`, `https://developer.android.com/reference/android/service/autofill/SaveInfo#FLAG_DONT_SAVE_ON_FINISH`, `https://developer.android.com/reference/android/service/autofill/SaveInfo#FLAG_DELAY_SAVE`, or `0`. Value is either `0` or a combination of the following: - `https://developer.android.com/reference/android/service/autofill/SaveInfo#FLAG_SAVE_ON_ALL_VIEWS_INVISIBLE` - `https://developer.android.com/reference/android/service/autofill/SaveInfo#FLAG_DONT_SAVE_ON_FINISH` - `https://developer.android.com/reference/android/service/autofill/SaveInfo#FLAG_DELAY_SAVE` |

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

### setNegativeAction

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

```
public SaveInfo.Builder setNegativeAction (int style, 
                IntentSender listener)
```

Sets the style and listener for the negative save action.

This allows an autofill service to customize the style and be
notified when the user selects the negative action in the save
UI. Note that selecting the negative action regardless of its style
and listener being customized would dismiss the save UI and if a
custom listener intent is provided then this intent is
started. The default style is `https://developer.android.com/reference/android/service/autofill/SaveInfo#NEGATIVE_BUTTON_STYLE_CANCEL`

<br />

<br />

| Parameters ||
|---|---|
| `style` | `int`: The action style. Value is one of the following: - `https://developer.android.com/reference/android/service/autofill/SaveInfo#NEGATIVE_BUTTON_STYLE_CANCEL` - `https://developer.android.com/reference/android/service/autofill/SaveInfo#NEGATIVE_BUTTON_STYLE_REJECT` - `https://developer.android.com/reference/android/service/autofill/SaveInfo#NEGATIVE_BUTTON_STYLE_NEVER` |
| `listener` | `IntentSender`: The action listener. This value may be `null`. <br /> |

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

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | If the style is invalid |

**See also:**

- `https://developer.android.com/reference/android/service/autofill/SaveInfo#NEGATIVE_BUTTON_STYLE_CANCEL`
- `https://developer.android.com/reference/android/service/autofill/SaveInfo#NEGATIVE_BUTTON_STYLE_REJECT`
- `https://developer.android.com/reference/android/service/autofill/SaveInfo#NEGATIVE_BUTTON_STYLE_NEVER`

### setOptionalIds

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

```
public SaveInfo.Builder setOptionalIds (AutofillId[] ids)
```

Sets the ids of additional, optional views the service would be interested to save.

See `https://developer.android.com/reference/android/service/autofill/SaveInfo` for more info.

<br />

| Parameters ||
|---|---|
| `ids` | `AutofillId`: The ids of the optional views. This value cannot be `null`. <br /> |

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

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `ids` is `null` or empty, or if it contains any `null` entry. |

### setPositiveAction

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

```
public SaveInfo.Builder setPositiveAction (int style)
```

Sets the style for the positive save action.

This allows an autofill service to customize the style of the
positive action in the save UI. Note that selecting the positive
action regardless of its style would dismiss the save UI and calling
into the `https://developer.android.com/reference/android/service/autofill/AutofillService#onSaveRequest(android.service.autofill.SaveRequest,%20android.service.autofill.SaveCallback)`.
The service should take the next action if selecting style
`https://developer.android.com/reference/android/service/autofill/SaveInfo#POSITIVE_BUTTON_STYLE_CONTINUE`. The default style is
`https://developer.android.com/reference/android/service/autofill/SaveInfo#POSITIVE_BUTTON_STYLE_SAVE`

<br />

| Parameters ||
|---|---|
| `style` | `int`: The action style. Value is one of the following: - `https://developer.android.com/reference/android/service/autofill/SaveInfo#POSITIVE_BUTTON_STYLE_SAVE` - `https://developer.android.com/reference/android/service/autofill/SaveInfo#POSITIVE_BUTTON_STYLE_CONTINUE` |

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

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | If the style is invalid |

**See also:**

- `https://developer.android.com/reference/android/service/autofill/SaveInfo#POSITIVE_BUTTON_STYLE_SAVE`
- `https://developer.android.com/reference/android/service/autofill/SaveInfo#POSITIVE_BUTTON_STYLE_CONTINUE`

### setTriggerId

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

```
public SaveInfo.Builder setTriggerId (AutofillId id)
```

Explicitly defines the view that should commit the autofill context when clicked.

Usually, the save request is only automatically
[triggered](https://developer.android.com/reference/android/service/autofill/SaveInfo.Builder#TriggeringSaveRequest) after the activity is
finished or all relevant views become invisible, but there are scenarios where the
autofill context is automatically commited too late
---for example, when the activity manually clears the autofillable views when a
button is tapped. This method can be used to trigger the autofill save UI earlier in
these scenarios.

**Note:** This method should only be used in scenarios where the automatic workflow
is not enough, otherwise it could trigger the autofill save UI when it should not---
for example, when the user entered invalid credentials for the autofillable views.

<br />

| Parameters ||
|---|---|
| `id` | `AutofillId`: This value cannot be `null`. <br /> |

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

### setValidator

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

```
public SaveInfo.Builder setValidator (Validator validator)
```

Sets an object used to validate the user input - if the input is not valid, the
autofill save UI is not shown.

Typically used to validate credit card numbers. Examples:

Validator for a credit number that must have exactly 16 digits:

```text
 Validator validator = new RegexValidator(ccNumberId, Pattern.compile(""^\\d{16}$"))
 
```

Validator for a credit number that must pass a Luhn checksum and either have
16 digits, or 15 digits starting with 108:

```python
 import static android.service.autofill.Validators.and;
 import static android.service.autofill.Validators.or;

 Validator validator =
   and(
     new LuhnChecksumValidator(ccNumberId),
     or(
       new RegexValidator(ccNumberId, Pattern.compile("^\\d{16}$")),
       new RegexValidator(ccNumberId, Pattern.compile("^108\\d{12}$"))
     )
   );
 
```

**Note:** the example above is just for illustrative purposes; the same validator
could be created using a single regex for the `OR` part:

```text
 Validator validator =
   and(
     new LuhnChecksumValidator(ccNumberId),
     new RegexValidator(ccNumberId, Pattern.compile(""^(\\d{16}|108\\d{12})$"))
   );
 
```

Validator for a credit number contained in just 4 fields and that must have exactly
4 digits on each field:

```python
 import static android.service.autofill.Validators.and;

 Validator validator =
   and(
     new RegexValidator(ccNumberId1, Pattern.compile("^\\d{4}$")),
     new RegexValidator(ccNumberId2, Pattern.compile("^\\d{4}$")),
     new RegexValidator(ccNumberId3, Pattern.compile("^\\d{4}$")),
     new RegexValidator(ccNumberId4, Pattern.compile("^\\d{4}$"))
   );
 
```

<br />

<br />

| Parameters ||
|---|---|
| `validator` | `Validator`: an implementation provided by the Android System. This value cannot be `null`. <br /> |

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

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `validator` is not a class provided by the Android System. |