Android autofill: dispatchProvideAutofillStructure() not laid out
Asked Answered
G

5

17

I have configured my app to support Android Oreo with compileSdkVersion 26. I've also set up android:autofillHints="phone" for my phone number input field. When I tap on the field, I can see "Autofill" popping up. However, when I tap on "Autofill", "Contents can't be autofilled" toast appears and I see the following trace in logcat:

RemoteFillService  Not handling { when=-3ms what=3 target=com.android.internal.os.HandlerCaller$MyHandler } as service for ComponentInfo{com.google.android.gms/com.google.android.gms.autofill.service.AutofillService} is already destroyed
View               dispatchProvideAutofillStructure(): not laid out, ignoring

How should I fix this? I've confirmed that I have the phone number configured in Settings > System > Languages & input > Advanced > Input assistance > Autofill service.

UPDATE with a sample XML: In API 26 emulator settings, I can select "Autofill with Google". Using the Design tab of Android Studio, I added a "Phone" type EditText, and then manually inserted android:autofillHints="phone" in the XML element:

<EditText
    android:id="@+id/editText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="phone"
    android:autofillHints="phone" />

Logcat peculiarities described above can be observed using this XML.

Glabrous answered 11/8, 2017 at 5:14 Comment(5)
There's nothing special in the XML or code other than the newly added android:autofillHints="phone". I'll try to find some time to elaborate. However, Autofill with Google seems to be a bit immature feature in its current status: plus.google.com/+JuusoOhtonen/posts/4kzMk5LUGLWGlabrous
First: No, I have not put an 250 bounty on it. Second: As I show in the Google Plus post, I currently cannot even select "Autofill with Google", so I really can't provide a verifiable example (as I cannot currently verify it by myself).Glabrous
I could use "Autofill with Google" on API 26 emulator. Based on that, I updated the question to include an XML element.Glabrous
Now working 1.9.17Seedbed
Update: After today's update for my Google Pixel XL device, autofill works perfectly (without additional code changes)!Glabrous
G
0

Get the latest OS image. After downloading and installing the update that became available on 2017-09-21 for my Google Pixel XL device, autofill works perfectly. So, it suffices to have android:autofillHints="phone" in XML, no other changes are required to enable the autofill feature.

Glabrous answered 21/9, 2017 at 9:26 Comment(0)
C
8

I'm the Android Frameworks engineer leading the Autofill Framework project, so I'll answer some questions:

  • The "Contents can't be autofilled" message typically means the Autofill Service does not know how to autofill the screen. When you're adding autofill support to your app, it's often easier to use an Autofill Service you can control first, rather than a "real" service like a password manager. As mentioned in a previous reply, we provide a sample service that can be used for this purpose.
  • When you long-press a text field and select AUTOFILL, you are in fact "forcing" an autofill request as mentioned in another reply (i.e., behind the scenes the text field is calling AutofillManager.requestAutofill()). If the Autofill Service knows how to autofill your screen, you shouldn't need to do that, as the autofill suggestions would show up right away once you focus the input field.
  • You shouldn't need to set importantForAutofill or call AutofillManager.cancel() in your case.

So, my recommendation is to try to use the sample Autofill Service implementation to test your app first. Most likely, the first time you access your app the autofill popup won't be shown because the service does not have data for it. But once your app triggers the save UI (for example, after you manually enter the phone number and the activity finishes) and you tap save, that data should be available the next time you launch the activity.

Hope that helps,

-- Felipe

Cavie answered 7/9, 2017 at 19:12 Comment(3)
My app works differently on the updated Nexus 5X API 26 emulator, on which autofill works perfectly (even without long-press). OTOH, Google Nexus XL, a real device, with the beta program image does not provide autofill for the same app, not even after long-press. Is there an update coming for the beta program (as there seems to have been one for the emulator)?Glabrous
Update: After today's update for my Google Pixel XL device, autofill works perfectly (without additional code changes)!Glabrous
@Felipe Leme, Could you please explain, why would autofill populate wrong EditText field?Blithering
B
2

This may well be the issue - as

as service for ComponentInfo{com.google.android.gms/com.google.android.gms.autofill.service.AutofillService} is already destroyed

Ensuring data is available
In some special cases, you need to take additional steps to make sure that the data is available to the Autofill Framework to save. For example, an activity can present a layout with standard text views, but then destroy the layout and replace it with one without child views, such as GLSurfaceView.

In this case, the data in the original layout is not available to the framework. To make the data available to the framework, you should call commit() on the AutofillManager object before replacing the original layout.

You'll need to fix some of these issues within your java code.

Add IMPORTANT_FOR_AUTOFILL_AUTO and check that autofill isenabled().

You may need to manage some of the settings within the java force the Autofill request:

Sometimes, you may need to force an autofill request to occur in response to a user action. .../...

public void eventHandler(View view) {
    AutofillManager afm = context.getSystemService(AutofillManager.class);
    if (afm != null) {
        afm.requestAutofill();
    }
}
Bilious answered 29/8, 2017 at 10:10 Comment(2)
Thanks, I took the first shot but I was not yet able to fix my code yet. I'll continue.Glabrous
Hmm, after updating the emulator to latest 8.0, autofill started to work without any additional code changes. I wonder if there's an update coming soon to real devices as well...Glabrous
C
0

Do you have an app on you phone that implements an Autofill service? I tried it with "Autofill with Google" service, and could got my phone number autofilled without problems (with emulator running SDK 26). You will need a service part for get the autofill working. See this example.

Crissie answered 28/8, 2017 at 13:42 Comment(1)
Thanks for the tip about using emulator. Based on that, I'm able to update my question.Glabrous
G
0

Get the latest OS image. After downloading and installing the update that became available on 2017-09-21 for my Google Pixel XL device, autofill works perfectly. So, it suffices to have android:autofillHints="phone" in XML, no other changes are required to enable the autofill feature.

Glabrous answered 21/9, 2017 at 9:26 Comment(0)
F
0

The "Contents can't be autofilled" - this was caused for me because i did not agree to the auto fill service. So go into your android settings in Oreo and above and search for "autofill" . find your service (mine was default googles) and there should be a prompt to agree to its service. toggle it off and one if it does not appear. Afterwards i was able to use autofill.

Fromenty answered 22/12, 2017 at 4:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.