Beginning in Android 11, keyboards and other input-method editors (IMEs) can display autofill suggestions inline, in a suggestion strip, or something similar instead of the system displaying suggestions in a menu. Since these autofill suggestions can contain private data, such as passwords or credit-card information, the suggestions are hidden from the IME until the user selects one. Update IMEs and autofill services, such as password managers, to make use of this feature. If an IME or a autofill service doesn't support inline autofill, suggestions are shown in a menu, as in versions earlier than Android 11.
Workflow
In this flow, IME means the current keyboard or other input editor, and suggestion provider means the appropriate provider of the autofill suggestion. Depending on the input field and the user's settings, the suggestion provider might be the platform or an autofill service.
-
The user focuses on an input field that triggers autofill, like a password or credit-card input field.
The platform queries the current IME and the appropriate suggestion provider to see whether they support inline autofill. If either the IME or the suggestion provider doesn't support inline autofill, the suggestion is shown in a menu, as on Android 10 and lower.
The platform asks the IME to provide a suggestion request. This suggestion request specifies the maximum number of suggestions to be displayed and also provides presentation specs for each suggestion. The presentation specs specify things like maximum size, text size, colors, and font data, letting the suggestion provider match the look and feel of the IME.
The platform asks the suggestion provider to provide up to the requested number of suggestions. Each suggestion includes a callback to inflate a
View
containing the suggestion's UI.The platform informs the IME that suggestions are ready. The IME displays the suggestions by calling the callback method to inflate each suggestion's
View
. To protect the user's private information, the IME does not see what the suggestions are at this stage.If the user selects one of the suggestions, the IME is informed the same way as if the user picks a suggestion from a system menu.
The following sections describe how to configure your IME or autofill service to support inline autofill.
Configure IMEs to support inline autofill
This section describes how to configure your IME to support inline autofill. If your IME doesn't support inline autofill, the platform defaults to showing autofill suggestions in a menu.
Your IME must set the supportsInlinedSuggestions
attribute to
true
:
<input-method
xmlns:android="http://schemas.android.com/apk/res/android"
android:supportsInlineSuggestions="true"/>
When the platform needs an autofill suggestion, it calls your IME's
InputMethodService.onCreateInlineSuggestionsRequest()
method. You must implement this method. Return an
InlineSuggestionsRequest
specifying the following:
- How many suggestions your IME wants.
An
InlinePresentationSpec
for each suggestion, defining how the suggestion must be presented.
When the platform has suggestions, it calls your IME's
onInlineSuggestionsResponse()
method, passing an
InlineSuggestionsResponse
containing the suggestions. You must implement this method. In your
implementation, call
InlineSuggestionsResponse.getInlineSuggestions()
to get the list of suggestions, then inflate each suggestion by calling its
InlineSuggestion.inflate()
method.
Configure autofill services to support inline autofill
This section describes how to configure your autofill service to support inline autofill. If your app doesn't support inline autofill, the platform defaults to showing its autofill suggestions in a menu.
Your autofill service must set the supportsInlinedSuggestions
attribute to
true
:
<autofill-service
xmlns:android="http://schemas.android.com/apk/res/android"
android:supportsInlineSuggestions="true"/>
When the IME needs autofill suggestions, the platform calls your autofill
service's
onFillRequest()
method, just as it does in versions below Android 11. However, your
service must call the passed FillRequest
object's
getInlineSuggestionsRequest()
method to get the InlineSuggestionsRequest
created by the IME. The
InlineSuggestionsRequest
specifies how many inline suggestions are needed and
how each one must be presented. If the IME doesn't support inline suggestions,
the method returns null
.
Your autofill service creates
InlinePresentation
objects, up to the maximum number requested in the InlineSuggestionsRequest
.
Your presentations must obey the size constraints specified by the
InlineSuggestionsRequest
. To return your suggestions to the IME, call
Dataset.Builder.setValue()
once for each suggestion. Android 11 provides versions of
Dataset.Builder.setValue()
to support inline suggestions.