Language

SaveInfo.Builder.AddSanitizer(ISanitizer, AutofillId[]) Method

Definition

Adds a sanitizer for one or more field.

[Android.Runtime.Register("addSanitizer", "(Landroid/service/autofill/Sanitizer;[Landroid/view/autofill/AutofillId;)Landroid/service/autofill/SaveInfo$Builder;", "", ApiSince=28)]
public Android.Service.Autofill.SaveInfo.Builder AddSanitizer(Android.Service.Autofill.ISanitizer sanitizer, params Android.Views.Autofill.AutofillId[] ids);
[<Android.Runtime.Register("addSanitizer", "(Landroid/service/autofill/Sanitizer;[Landroid/view/autofill/AutofillId;)Landroid/service/autofill/SaveInfo$Builder;", "", ApiSince=28)>]
member this.AddSanitizer : Android.Service.Autofill.ISanitizer * Android.Views.Autofill.AutofillId[] -> Android.Service.Autofill.SaveInfo.Builder

Parameters

sanitizer
ISanitizer

an implementation provided by the Android System. This value cannot be null.

ids
AutofillId[]

id of fields whose value will be sanitized. This value cannot be null.

Returns

this builder. This value cannot be null.

Attributes

Remarks

Adds a sanitizer for one or more field.

When a sanitizer is set for a field, the AutofillValue is sent to the sanitizer before a save request is triggered.

Typically used to avoid displaying the save UI for values that are autofilled but reformattedby the app.

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.

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

The sanitizer can also be used as an alternative for a validator. If any of the ids is a required id and the sanitizer fails because of it, then the save UI is not shown.

Android reference for android.service.autofill.SaveInfo.Builder.addSanitizer.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to