How can I get the AutoFillHint/HintText/Text from another app structure?

145 Views Asked by At

I'm creating an AutoFillService on my android password management app (using java).

I have followed this turotial

While my service is trying to get the content of another app, it seems like it can't detect AutofillHint, Hint and Text inside the fields.

Here is my code inside the onFillRequest method from AutoFillService superclass :

// Get the structure from the request
List<FillContext> context = request.getFillContexts();
AssistStructure structure = context.get(context.size() - 1).getStructure();
this.appToFillName = structure.getActivityComponent().getPackageName();
System.out.println("Fill request : " + this.appToFillName);
// Traverse the structure looking for nodes to fill out.
int nodes = structure.getWindowNodeCount();
for (int i = 0; i < nodes; i++) {
    AssistStructure.ViewNode viewNode = 
    structure.getWindowNodeAt(i).getRootViewNode();
    traverseNode(viewNode);
}

And then I go through the node with my traverseNode method :

public void traverseNode(@NonNull AssistStructure.ViewNode viewNode) {
    //my problem is that I see null objects/nothing coming out of this print function
    //even when I'm on an app where I know there are field with AutofillHints
    System.out.println(Arrays.toString(viewNode.getAutofillHints()) + "\n" + viewNode.getHint() + "\n" + viewNode.getText());
    //here I have some methods to link the autofillId when I detect a field to fill ...
    for (int i = 0; i < viewNode.getChildCount(); i++) {
        AssistStructure.ViewNode childNode = viewNode.getChildAt(i);
        traverseNode(childNode);
    }
}

Thank's for your help !

1

There are 1 best solutions below

0
On

I don't believe viewNode will have any associated autofill hints. Instead, it's the children that have hints associated (i.e. each fillable field rather than the entire frame). Try printing out autofill hints associated with each childNode instead.