Share via


View.OnProvideAutofillStructure(ViewStructure, AutofillFlags) Method

Definition

Populates a ViewStructure to fullfil an autofill request.

[Android.Runtime.Register("onProvideAutofillStructure", "(Landroid/view/ViewStructure;I)V", "GetOnProvideAutofillStructure_Landroid_view_ViewStructure_IHandler", ApiSince=26)]
public virtual void OnProvideAutofillStructure (Android.Views.ViewStructure? structure, Android.Views.AutofillFlags flags);
[<Android.Runtime.Register("onProvideAutofillStructure", "(Landroid/view/ViewStructure;I)V", "GetOnProvideAutofillStructure_Landroid_view_ViewStructure_IHandler", ApiSince=26)>]
abstract member OnProvideAutofillStructure : Android.Views.ViewStructure * Android.Views.AutofillFlags -> unit
override this.OnProvideAutofillStructure : Android.Views.ViewStructure * Android.Views.AutofillFlags -> unit

Parameters

structure
ViewStructure

fill in with structured view data for autofill purposes.

flags
AutofillFlags

optional flags.

Attributes

Remarks

Populates a ViewStructure to fullfil an autofill request.

The structure should contain at least the following properties: <ul> <li>Autofill id (ViewStructure#setAutofillId(AutofillId, int)). <li>Autofill type (ViewStructure#setAutofillType(int)). <li>Autofill value (ViewStructure#setAutofillValue(AutofillValue)). <li>Whether the data is sensitive (ViewStructure#setDataIsSensitive(boolean)). </ul>

It's also recommended to set the following properties - the more properties the structure has, the higher the chances of an android.service.autofill.AutofillService properly using the structure:

<ul> <li>Autofill hints (ViewStructure#setAutofillHints(String[])). <li>Autofill options (ViewStructure#setAutofillOptions(CharSequence[])) when the view can only be filled with predefined values (typically used when the autofill type is #AUTOFILL_TYPE_LIST). <li>Resource id (ViewStructure#setId(int, String, String, String)). <li>Class name (ViewStructure#setClassName(String)). <li>Content description (ViewStructure#setContentDescription(CharSequence)). <li>Visual properties such as visibility (ViewStructure#setVisibility(int)), dimensions (ViewStructure#setDimens(int, int, int, int, int, int)), and opacity (ViewStructure#setOpaque(boolean)). <li>For views representing text fields, text properties such as the text itself (ViewStructure#setText(CharSequence)), text hints (ViewStructure#setHint(CharSequence), input type (ViewStructure#setInputType(int)), <li>For views representing HTML nodes, its web domain (ViewStructure#setWebDomain(String)) and HTML properties ((ViewStructure#setHtmlInfo(android.view.ViewStructure.HtmlInfo)). </ul>

The default implementation of this method already sets most of these properties based on related View methods (for example, the autofill id is set using #getAutofillId(), the autofill type set using #getAutofillType(), etc.), and views in the standard Android widgets library also override it to set their relevant properties (for example, android.widget.TextView already sets the text properties), so it's recommended to only override this method (and call super.onProvideAutofillStructure()) when:

<ul> <li>The view contents does not include PII (Personally Identifiable Information), so it can call ViewStructure#setDataIsSensitive(boolean) passing false. <li>The view can only be autofilled with predefined options, so it can call ViewStructure#setAutofillOptions(CharSequence[]). </ul>

<b>Note:</b> The left and top values set in ViewStructure#setDimens(int, int, int, int, int, int) must be relative to the next ViewGroup#isImportantForAutofill() predecessor view included in the structure.

Views support the Autofill Framework mainly by: <ul> <li>Providing the metadata defining what the view means and how it can be autofilled. <li>Notifying the Android System when the view value changed by calling AutofillManager#notifyValueChanged(View). <li>Implementing the methods that autofill the view. </ul>

This method is responsible for the former; #autofill(AutofillValue) is responsible for the latter.

Java documentation for android.view.View.onProvideAutofillStructure(android.view.ViewStructure, int).

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