# Print output for @column tags ?>
Developers

- Design
- Develop
- Distribute

Developer Console

## Most visited

## Recently visited

## Results for

Summary: Nested Classes | Constants | Methods | Inherited Methods

# AutofillManager

`public final class AutofillManager`
`extends Object` ``

java.lang.Object
↳ | android.view.autofill.AutofillManager

The `AutofillManager` class provides ways for apps and custom views to integrate with the Autofill Framework lifecycle.

To learn about using Autofill in your app, read the Autofill Framework guides.

### Autofill lifecycle

The autofill lifecycle starts with the creation of an autofill context associated with an activity context. The autofill context is created when one of the following methods is called for the first time in an activity context, and the current user has an enabled autofill service:

- `notifyViewEntered(android.view.View)`
- `notifyViewEntered(android.view.View, int, android.graphics.Rect)`
- `requestAutofill(android.view.View)`

Typically, the context is automatically created when the first view of the activity is focused because `View.onFocusChanged()` indirectly calls `notifyViewEntered(android.view.View)`. App developers can call `requestAutofill(android.view.View)` to explicitly create it (for example, a custom view developer could offer a contextual menu action in a text-field view to let users manually request autofill).

After the context is created, the Android System creates a `ViewStructure` that represents the view hierarchy by calling `View#dispatchProvideAutofillStructure(android.view.ViewStructure, int)` in the root views of all application windows. By default, `dispatchProvideAutofillStructure()` results in subsequent calls to `View#onProvideAutofillStructure(android.view.ViewStructure, int)` and `View#onProvideAutofillVirtualStructure(android.view.ViewStructure, int)` for each view in the hierarchy.

The resulting `ViewStructure` is then passed to the autofill service, which parses it looking for views that can be autofilled. If the service finds such views, it returns a data structure to the Android System containing the following optional info:

- Datasets used to autofill subsets of views in the activity.
- Id of views that the service can save their values for future autofilling.

When the service returns datasets, the Android System displays an autofill dataset picker UI associated with the view, when the view is focused on and is part of a dataset. The application can be notified when the UI is shown by registering an `AutofillCallback` through `registerCallback(android.view.autofill.AutofillManager.AutofillCallback)`. When the user selects a dataset from the UI, all views present in the dataset are autofilled, through calls to `View#autofill(AutofillValue)` or `View#autofill(SparseArray)`.

When the service returns ids of savable views, the Android System keeps track of changes made to these views, so they can be used to determine if the autofill save UI is shown later.

The context is then finished when one of the following occurs:

- `commit()` is called or all savable views are gone.
- `cancel()` is called.

Finally, after the autofill context is commited (i.e., not cancelled), the Android System shows an autofill save UI if the value of savable views have changed. If the user selects the option to Save, the current value of the views is then sent to the autofill service.

### Additional notes

It is safe to call `AutofillManager` methods from any thread.
Requires the `PackageManager#FEATURE_AUTOFILL` feature which can be detected using `PackageManager.hasSystemFeature(String)`.

## Summary

### Nested classes
`class` | `AutofillManager.AutofillCallback` Callback for autofill related events.

### Constants
`String` | `EXTRA_ASSIST_STRUCTURE` Intent extra: The assist structure which captures the filled screen.
`String` | `EXTRA_AUTHENTICATION_RESULT` Intent extra: The result of an authentication operation.
`String` | `EXTRA_CLIENT_STATE` Intent extra: The optional extras provided by the `AutofillService`.

### Public methods
`void` | `cancel()` Called to indicate the current autofill context should be cancelled.
`void` | `commit()` Called to indicate the current autofill context should be commited.
`void` | `disableAutofillServices()` If the app calling this API has enabled autofill services they will be disabled.
`ComponentName` | `getAutofillServiceComponentName()` Returns the component name of the `AutofillService` that is enabled for the current user.
`List<String>` | `getAvailableFieldClassificationAlgorithms()` Gets the name of all algorithms currently available for field classification.
`String` | `getDefaultFieldClassificationAlgorithm()` Gets the name of the default algorithm used for field classification.
`AutofillId` | `getNextAutofillId()` Gets the next unique autofill ID for the activity context.
`UserData` | `getUserData()` Gets the user data used for field classification.
`String` | `getUserDataId()` Gets the id of the `UserData` used for field classification.
`boolean` | `hasEnabledAutofillServices()` Returns `true` if the calling application provides a `AutofillService` that is enabled for the current user, or `false` otherwise.
`boolean` | `isAutofillSupported()` Returns `true` if autofill is supported by the current device and is supported for this user.
`boolean` | `isEnabled()` Checks whether autofill is enabled for the current user.
`boolean` | `isFieldClassificationEnabled()` Checks if field classification is enabled.
`void` | `notifyValueChanged(View view)` Called to indicate the value of an autofillable `View` changed.
`void` | `notifyValueChanged(View view, int virtualId, AutofillValue value)` Called to indicate the value of an autofillable virtual view has changed.
`void` | `notifyViewClicked(View view)` Called to indicate a `View` is clicked.
`void` | `notifyViewClicked(View view, int virtualId)` Called to indicate a virtual view has been clicked.
`void` | `notifyViewEntered(View view)` Called when a `View` that supports autofill is entered.
`void` | `notifyViewEntered(View view, int virtualId, Rect absBounds)` Called when a virtual view that supports autofill is entered.
`void` | `notifyViewExited(View view, int virtualId)` Called when a virtual view that supports autofill is exited.
`void` | `notifyViewExited(View view)` Called when a `View` that supports autofill is exited.
`void` | `notifyViewVisibilityChanged(View view, int virtualId, boolean isVisible)` Called when a virtual view's visibility changed.
`void` | `notifyViewVisibilityChanged(View view, boolean isVisible)` Called when a `View` visibility changed.
`void` | `registerCallback(AutofillManager.AutofillCallback callback)` Registers a `AutofillCallback` to receive autofill events.
`void` | `requestAutofill(View view, int virtualId, Rect absBounds)` Explicitly requests a new autofill context for virtual views.
`void` | `requestAutofill(View view)` Explicitly requests a new autofill context.
`void` | `setUserData(UserData userData)` Sets the `UserData` used for field classification Note: This method should only be called by an app providing an autofill service, and it's ignored if the caller currently doesn't have an enabled autofill service for the user.
`void` | `unregisterCallback(AutofillManager.AutofillCallback callback)` Unregisters a `AutofillCallback` to receive autofill events.

### Inherited methods
From class `java.lang.Object`
`Object` | `clone()` Creates and returns a copy of this object.
`boolean` | `equals(Object obj)` Indicates whether some other object is "equal to" this one.
`void` | `finalize()` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
`final Class<?>` | `getClass()` Returns the runtime class of this `Object`.
`int` | `hashCode()` Returns a hash code value for the object.
`final void` | `notify()` Wakes up a single thread that is waiting on this object's monitor.
`final void` | `notifyAll()` Wakes up all threads that are waiting on this object's monitor.
`String` | `toString()` Returns a string representation of the object.
`final void` | `wait(long timeout, int nanos)` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
`final void` | `wait(long timeout)` Causes the current thread to wait until either another thread invokes the `notify()` method or the `notifyAll()` method for this object, or a specified amount of time has elapsed.
`final void` | `wait()` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object.

## Constants

### EXTRA_ASSIST_STRUCTURE

    public static final String EXTRA_ASSIST_STRUCTURE

Intent extra: The assist structure which captures the filled screen.

Type: `AssistStructure`

Constant Value: "android.view.autofill.extra.ASSIST_STRUCTURE"

### EXTRA_AUTHENTICATION_RESULT

    public static final String EXTRA_AUTHENTICATION_RESULT

Intent extra: The result of an authentication operation. It is either a fully populated `FillResponse` or a fully populated `Dataset` if a response or a dataset is being authenticated respectively.

Type: `FillResponse` or a `Dataset`

Constant Value: "android.view.autofill.extra.AUTHENTICATION_RESULT"

### EXTRA_CLIENT_STATE

    public static final String EXTRA_CLIENT_STATE

Intent extra: The optional extras provided by the `AutofillService`.

For example, when the service responds to a `FillCallback.onSuccess(android.service.autofill.FillResponse)` with a `FillResponse` that requires authentication, the Intent that launches the service authentication will contain the Bundle set by `FillResponse.Builder.setClientState(Bundle)` on this extra.

On Android `Build.VERSION_CODES.P` and higher, the autofill service can also add this bundle to the `Intent` set as the `result` for an authentication request, so the bundle can be recovered later on `SaveRequest.getClientState()`.

Type: `Bundle`

Constant Value: "android.view.autofill.extra.CLIENT_STATE"

## Public methods

### cancel

    public void cancel ()

Called to indicate the current autofill context should be cancelled.

This method is typically called by `View` that manage virtual views; for example, when the view is rendering an `HTML` page with a form and virtual views that represent the HTML elements, it should call this method if the user does not post the form but moves to another form in this page.

Note: This method does not need to be called on regular application lifecycle methods such as `Activity.finish()`.

### commit

    public void commit ()

Called to indicate the current autofill context should be commited.

This method is typically called by `View` that manage virtual views; for example, when the view is rendering an `HTML` page with a form and virtual views that represent the HTML elements, it should call this method after the form is submitted and another page is rendered.

Note: This method does not need to be called on regular application lifecycle methods such as `Activity.finish()`.

### disableAutofillServices

    public void disableAutofillServices ()

If the app calling this API has enabled autofill services they will be disabled.

### getAutofillServiceComponentName

    public ComponentName getAutofillServiceComponentName ()

Returns the component name of the `AutofillService` that is enabled for the current user.

Returns
`ComponentName` | This value may be `null`.

### getAvailableFieldClassificationAlgorithms

    public List<String> getAvailableFieldClassificationAlgorithms ()

Gets the name of all algorithms currently available for field classification.

Note: This method should only be called by an app providing an autofill service, and it returns an empty list if the caller currently doesn't have an enabled autofill service for the user.

Returns
`List<String>` | This value cannot be `null`.

### getDefaultFieldClassificationAlgorithm

    public String getDefaultFieldClassificationAlgorithm ()

Gets the name of the default algorithm used for field classification.

The default algorithm is used when the algorithm on `UserData` is invalid or not set.

Note: This method should only be called by an app providing an autofill service, and it's ignored if the caller currently doesn't have an enabled autofill service for the user.

Returns
`String` | This value may be `null`.

### getNextAutofillId

    public AutofillId getNextAutofillId ()

Gets the next unique autofill ID for the activity context.

Typically used to manage views whose content is recycled - see `View#setAutofillId(AutofillId)` for more info.

Returns
`AutofillId` | An ID that is unique in the activity, or `null` if autofill is not supported in the `Context` associated with this `AutofillManager`.

### getUserData

    public UserData getUserData ()

Gets the user data used for field classification.

Note: This method should only be called by an app providing an autofill service, and it's ignored if the caller currently doesn't have an enabled autofill service for the user.

Returns
`UserData` | value previously set by `setUserData(android.service.autofill.UserData)` or `null` if it was reset or if the caller currently does not have an enabled autofill service for the user.

### getUserDataId

    public String getUserDataId ()

Gets the id of the `UserData` used for field classification.

This method is useful when the service must check the status of the `UserData` in the device without fetching the whole object.

Note: This method should only be called by an app providing an autofill service, and it's ignored if the caller currently doesn't have an enabled autofill service for the user.

Returns
`String` | id of the `UserData` previously set by `setUserData(android.service.autofill.UserData)` or `null` if it was reset or if the caller currently does not have an enabled autofill service for the user.

### hasEnabledAutofillServices

    public boolean hasEnabledAutofillServices ()

Returns `true` if the calling application provides a `AutofillService` that is enabled for the current user, or `false` otherwise.

Returns
`boolean` |

### isAutofillSupported

    public boolean isAutofillSupported ()

Returns `true` if autofill is supported by the current device and is supported for this user.

Autofill is typically supported, but it could be unsupported in cases like:

1. Low-end devices.
2. Device policy rules that forbid its usage.

Returns
`boolean` |

### isEnabled

    public boolean isEnabled ()

Checks whether autofill is enabled for the current user.

Typically used to determine whether the option to explicitly request autofill should be offered - see `requestAutofill(android.view.View)`.

Returns
`boolean` | whether autofill is enabled for the current user.

### isFieldClassificationEnabled

    public boolean isFieldClassificationEnabled ()

Checks if field classification is enabled.

As field classification is an expensive operation, it could be disabled, either temporarily (for example, because the service exceeded a rate-limit threshold) or permanently (for example, because the device is a low-level device).

Note: This method should only be called by an app providing an autofill service, and it's ignored if the caller currently doesn't have an enabled autofill service for the user.

Returns
`boolean` |

### notifyValueChanged

    public void notifyValueChanged (View view)

Called to indicate the value of an autofillable `View` changed.

Parameters
`view` | `View`: view whose value changed.

### notifyValueChanged

    public void notifyValueChanged (View view,
                    int virtualId,
                    AutofillValue value)

Called to indicate the value of an autofillable virtual view has changed.

Parameters
`view` | `View`: the virtual view parent.
`virtualId` | `int`: id identifying the virtual child inside the parent view.
`value` | `AutofillValue`: new value of the child.

### notifyViewClicked

    public void notifyViewClicked (View view)

Called to indicate a `View` is clicked.

Parameters
`view` | `View`: view that has been clicked. This value cannot be `null`.

### notifyViewClicked

    public void notifyViewClicked (View view,
                    int virtualId)

Called to indicate a virtual view has been clicked.

Parameters
`view` | `View`: the virtual view parent. This value cannot be `null`.
`virtualId` | `int`: id identifying the virtual child inside the parent view.

### notifyViewEntered

    public void notifyViewEntered (View view)

Called when a `View` that supports autofill is entered.

Parameters
`view` | `View`: `View` that was entered. This value cannot be `null`.

### notifyViewEntered

    public void notifyViewEntered (View view,
                    int virtualId,
                    Rect absBounds)

Called when a virtual view that supports autofill is entered.

The virtual view boundaries must be absolute screen coordinates. For example, if the parent, non-virtual view uses `bounds` to draw the virtual view inside its Canvas, the absolute bounds could be calculated by:

       int offset[] = new int[2];
       getLocationOnScreen(offset);
       Rect absBounds = new Rect(bounds.left + offset[0],
           bounds.top + offset[1],
           bounds.right + offset[0], bounds.bottom + offset[1]);

Parameters
`view` | `View`: the virtual view parent. This value cannot be `null`.
`virtualId` | `int`: id identifying the virtual child inside the parent view.
`absBounds` | `Rect`: absolute boundaries of the virtual view in the screen. This value cannot be `null`.

### notifyViewExited

    public void notifyViewExited (View view,
                    int virtualId)

Called when a virtual view that supports autofill is exited.

Parameters
`view` | `View`: the virtual view parent. This value cannot be `null`.
`virtualId` | `int`: id identifying the virtual child inside the parent view.

### notifyViewExited

    public void notifyViewExited (View view)

Called when a `View` that supports autofill is exited.

Parameters
`view` | `View`: `View` that was exited. This value cannot be `null`.

### notifyViewVisibilityChanged

    public void notifyViewVisibilityChanged (View view,
                    int virtualId,
                    boolean isVisible)

Called when a virtual view's visibility changed.

Parameters
`view` | `View`: `View` that was exited. This value cannot be `null`.
`virtualId` | `int`: id identifying the virtual child inside the parent view.
`isVisible` | `boolean`: visible if the view is visible in the view hierarchy.

### notifyViewVisibilityChanged

    public void notifyViewVisibilityChanged (View view,
                    boolean isVisible)

Called when a `View` visibility changed.

Parameters
`view` | `View`: `View` that was exited. This value cannot be `null`.
`isVisible` | `boolean`: visible if the view is visible in the view hierarchy.

### registerCallback

    public void registerCallback (AutofillManager.AutofillCallback callback)

Registers a `AutofillCallback` to receive autofill events.

Parameters
`callback` | `AutofillManager.AutofillCallback`: callback to receive events. This value may be `null`.

### requestAutofill

    public void requestAutofill (View view,
                    int virtualId,
                    Rect absBounds)

Explicitly requests a new autofill context for virtual views.

Normally, the autofill context is automatically started if necessary when `notifyViewEntered(android.view.View, int, android.graphics.Rect)` is called, but this method should be used in the cases where it must be explicitly started. For example, when the virtual view offers an AUTOFILL option on its contextual overflow menu, and the user selects it.

The virtual view boundaries must be absolute screen coordinates. For example, if the parent view uses `bounds` to draw the virtual view inside its Canvas, the absolute bounds could be calculated by:

       int offset[] = new int[2];
       getLocationOnScreen(offset);
       Rect absBounds = new Rect(bounds.left + offset[0],
           bounds.top + offset[1],
           bounds.right + offset[0], bounds.bottom + offset[1]);

Parameters
`view` | `View`: the virtual view parent. This value cannot be `null`.
`virtualId` | `int`: id identifying the virtual child inside the parent view.
`absBounds` | `Rect`: absolute boundaries of the virtual view in the screen. This value cannot be `null`.

### requestAutofill

    public void requestAutofill (View view)

Explicitly requests a new autofill context.

Normally, the autofill context is automatically started if necessary when `notifyViewEntered(android.view.View)` is called, but this method should be used in the cases where it must be explicitly started. For example, when the view offers an AUTOFILL option on its contextual overflow menu, and the user selects it.

Parameters
`view` | `View`: view requesting the new autofill context. This value cannot be `null`.

### setUserData

    public void setUserData (UserData userData)

Sets the `UserData` used for field classification

Note: This method should only be called by an app providing an autofill service, and it's ignored if the caller currently doesn't have an enabled autofill service for the user.

Parameters
`userData` | `UserData`: This value may be `null`.

### unregisterCallback

    public void unregisterCallback (AutofillManager.AutofillCallback callback)

Unregisters a `AutofillCallback` to receive autofill events.

Parameters
`callback` | `AutofillManager.AutofillCallback`: callback to stop receiving events. This value may be `null`.

Full name *
Email address *
Company / developer name
One of your Play Store app URLs *
Which best describes your business:*
Apps
Games
Apps & Games
*
*