简体   繁体   中英

getWebDomain() function always returns null in Android AutoFill service

While implementing the Android AutoFill functionality for my password manager, I'm unable to get the domain name for the webpage with which the user is interacting. While testing other password managers, I see they are able to get the domain, because they are able to filter responses according to the domain stored on various records. For example, if I have 3 records that have “yahoo.com” as the domain and 6 other records with different domains, when I tap into the username field on Yahoo's sign in form, I'm only presented with the 3 records with “yahoo.com” as the domain, which is the correct functionality. In my own app, when I tap into the username field, I'm presented with all 9 records. I'm not able to get the domain needed to filter the records appropriately.

I studied the documentation in detail and used an example from Google for development.

I did not find any mention there may be any difficulties with getting the domain, but I am not able to get the data I need. Below is an example of how I am trying to get the domain name on a page.

public void onFillRequest(FillRequest request, CancellationSignal cancellationSignal, FillCallback callback) {
List<FillContext> context = request.getFillContexts();
AssistStructure structure = context.get(context.size() - 1).getStructure();

ArrayMap<String, AutofillId> fields = new ArrayMap<>();
int nodes = structure.getWindowNodeCount();
for (int i = 0; i < nodes; i++) {
    AssistStructure.ViewNode node = structure.getWindowNodeAt(i).getRootViewNode();
    String webDomain = node.getWebDomain();
    if (webDomain != null){
        Log.d(TAG,"domain: " + webDomain);
    }
    addAutofillableFields(fields, node);
}

FillResponse response = createResponse(this, fields);
callback.onSuccess(response);

}

I have not been able to get a real webDomain value. Only null…

It works fine in the apps due there I need only packageName for identifying the app. But for browser pages I need a page domain name.

I would be grateful if someone could tell me what I did wrong. The project is posted here -

Solved. web Domain name can be retrieved only from the one of the nodes from the node tree. I thought that it should be filled for each node.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM