Android Inline Autofill Suggestions IME: Not getting inline suggestions, auto fill shown as drop down

Viewed 312

I am trying to integrate inline autofill suggestions introduced in Android 11 with custom Android Keyboard. I am not getting any inline suggestions in onInlineSuggestionsResponse().

I have added android:supportsInlineSuggestions="true" in input-method xml file. I have overrided onCreateInlineSuggestionsRequest() in InputMethodService class and created InlineSuggestionRequest as below:

@Nullable
@Override
public InlineSuggestionsRequest onCreateInlineSuggestionsRequest(@NonNull Bundle uiExtras) {
    InlinePresentationSpec inlinePresentationSpec = new InlinePresentationSpec.Builder(
            new Size(50, 200),
            new Size(100,200)
    ).build();
    return new InlineSuggestionsRequest.Builder(
            Collections.singletonList(inlinePresentationSpec)
    ).setMaxSuggestionCount(InlineSuggestionsRequest.SUGGESTION_COUNT_UNLIMITED).setExtras(uiExtras)
            .build();
}

I have enabled Google Autofill service and used GBoard to check whether its getting inline suggestion and GBoard was showing autofill inline suggestions.

Also onInlineSuggestionsResponse() is not triggered after onCreateInlineSuggestionsRequest(). What I observed is, onInlineSuggestionsResponse() is called when I navigate from or to the activity containing edittext that request autofill suggestions. It will be called before onCreateInlineSuggestionsRequest().

Is there anything else I should enable in order to get inline Autofill suggestions?

1 Answers

You can refer to the android official git repository:

https://android.googlesource.com/platform/development/+/master/samples/AutofillKeyboard/

Here, they have clearly implemented the autofill inline suggestion. I have also developed an SDK from it for Mint Keyboard. If you need any help in implementing it, just ping it, and I'll help you out.

Attaching the code for onCreateInlineSuggestionsRequest():

@Override
public InlineSuggestionsRequest onCreateInlineSuggestionsRequest(Bundle uiExtras) {
    Log.d(TAG, "onCreateInlineSuggestionsRequest() called");
    StylesBuilder stylesBuilder = UiVersions.newStylesBuilder();
    Style style = InlineSuggestionUi.newStyleBuilder()
            .setSingleIconChipStyle(
                    new ViewStyle.Builder()
                            .setBackground(
                                    Icon.createWithResource(this, R.drawable.chip_background))
                            .setPadding(0, 0, 0, 0)
                            .build())
            .setChipStyle(
                    new ViewStyle.Builder()
                            .setBackground(
                                    Icon.createWithResource(this, R.drawable.chip_background))
                            .setPadding(toPixel(5 + 8), 0, toPixel(5 + 8), 0)
                            .build())
            .setStartIconStyle(new ImageViewStyle.Builder().setLayoutMargin(0, 0, 0, 0).build())
            .setTitleStyle(
                    new TextViewStyle.Builder()
                            .setLayoutMargin(toPixel(4), 0, toPixel(4), 0)
                            .setTextColor(Color.parseColor("#FF202124"))
                            .setTextSize(16)
                            .build())
            .setSubtitleStyle(
                    new TextViewStyle.Builder()
                            .setLayoutMargin(0, 0, toPixel(4), 0)
                            .setTextColor(Color.parseColor("#99202124")) // 60% opacity
                            .setTextSize(14)
                            .build())
            .setEndIconStyle(new ImageViewStyle.Builder().setLayoutMargin(0, 0, 0, 0).build())
            .build();
    stylesBuilder.addStyle(style);
    Bundle stylesBundle = stylesBuilder.build();
    final ArrayList<InlinePresentationSpec> presentationSpecs = new ArrayList<>();
    presentationSpecs.add(new InlinePresentationSpec.Builder(new Size(100, getHeight()),
            new Size(740, getHeight())).setStyle(stylesBundle).build());
    presentationSpecs.add(new InlinePresentationSpec.Builder(new Size(100, getHeight()),
            new Size(740, getHeight())).setStyle(stylesBundle).build());
    return new InlineSuggestionsRequest.Builder(presentationSpecs)
            .setMaxSuggestionCount(6)
            .build();
}
Related