2

I ran into problems when trying to use Autofill Framework for the login fragment, it does not show the save popup. I placed android:autofillHints attribute on both text fields, then I tried android:importantForAutofill="yes" on both with the same results, and I also tried to call AutofillManager.requestAutofill() and AutofillManager.commit() manually.

Next I downloaded an example from here and installed it, and it worked normally. I used debug to check AutofillManager in both apps and it turned out that AutofillManager.isEnabled() produces different results: true in a sample app and false in my app. In both cases I checked the first line of onCreate() in a first activity of an app, which in both cases does not contain fields to be filled.

That's why I think a problem is not in the code or layout files, but rather in the gradle or manifest files, but I could not find any difference in those that could have affected the Autofill Framework. I do not think that framework also has configuration values. I checked targetSdk and minSdk, but that's not it

What else should I check?

loredan13
  • 114
  • 1
  • 9
  • @g-ciardini, I would appreciate if you checked the edits you make, since you managed to completely butcher attribute names, bracket placing, placed a few unnecesary spaces, and removed link to an example – loredan13 Sep 18 '18 at 14:10
  • You have no guarantee that your app will trigger a save popup, because that depends on the autofill service implementation. If you want to make sure you're using the right `autofillHints`, I'd suggesting using the `Basic Autofill Service` from the (official samples)[https://github.com/googlesamples/android-AutofillFramework]. – Felipe Leme Oct 12 '18 at 17:44
  • You could also use the `Heuristics Autofill Service` (soon to be renamed `Debug Autofill Service`) if the service doesn't work - this one tries to autofill everything, which is useful for debugging. – Felipe Leme Oct 12 '18 at 17:52
  • Finally, you usually don't need to call `AutofillManager.requestAutofill()` or `AutofillManager.commit()`, these are meant for people developing custom views (for example, `requestAutofill()` is called by `EditText` when the user long-press a view and select AUTOFILL in the overflow menu), although `AutofillManager.commit()` could be used to indicate your workflow is done (for example, if you're using fragments to replace the screen after the user tapped "Login"). – Felipe Leme Oct 12 '18 at 17:52

2 Answers2

1

AutofillManager.isEnabled() should not produce different results on your app or the sample app, my guess is that you're using the wrong context to get the manager, it should be the Activity.

Felipe Leme
  • 181
  • 4
  • Might be, I am using Calligraphy, which wraps Context. I'll try unwrapping it – loredan13 Oct 11 '18 at 16:21
  • Ok, let me know if it works. FYI, the `AutofillManager.getClientLocked() changed from [https://android.googlesource.com/platform/frameworks/base/+/oreo-release/core/java/android/view/autofill/AutofillManager.java#763](8.0) to [8.1](https://android.googlesource.com/platform/frameworks/base/+/oreo-mr1-release/core/java/android/view/autofill/AutofillManager.java#939). – Felipe Leme Oct 12 '18 at 17:28
  • Sorry, here's the right links: [8.0](https://android.googlesource.com/platform/frameworks/base/+/oreo-release/core/java/android/view/autofill/AutofillManager.java#763) - [8.1](https://android.googlesource.com/platform/frameworks/base/+/oreo-mr1-release/core/java/android/view/autofill/AutofillManager.java#939). – Felipe Leme Oct 12 '18 at 17:33
  • No, unfortunately, that is not the case, I already get AutofillManager from Activity class or its descendant – loredan13 Oct 29 '18 at 09:58
  • Well, I'm out of ideas then :-( Can you reproduce the issue forking with the sample apps from https://github.com/googlesamples/android-AutofillFramework ? – Felipe Leme Oct 30 '18 at 16:54
  • I haven't been able to reproduce the issue in a different app so far. I'll try – loredan13 Oct 30 '18 at 17:01
0

You might need to Configure an autofill service and you need to add view data binding logic in the onProvideAutofillStructure method.

<!--
Declare AutofillService implementation; only needed for a small number of apps that will
be implementing an AutofillService. Framework parses meta-data and sets the service's
Settings Activity based on what the meta-data resource points to.
-->
    <service
        android:name=".MyAutofillService"
        android:label="Multi-Dataset Autofill Service"
        android:permission="android.permission.BIND_AUTOFILL_SERVICE">
        <meta-data
            android:name="android.autofill"
            android:resource="@xml/multidataset_service" />

        <intent-filter>
            <action android:name="android.service.autofill.AutofillService" />
        </intent-filter>
    </service>
Ramesh Yankati
  • 1,197
  • 9
  • 13
  • Isn't that for the apps that provide Autofill functionality, such as password managers (Samsung Pass, for example)? If so, that is not my case – loredan13 Oct 11 '18 at 16:40
  • +loredan13 is right, the autofill service is only need for apps such as password managers. As a "regular" app developer, there are some APIs you could use to optimize our app for autofill although `onProvideAutofillStructure()` is a extreme case - see https://developer.android.com/guide/topics/text/autofill-optimize for the common cases. – Felipe Leme Oct 12 '18 at 17:22