【发布时间】:2022-12-21 05:08:32
【问题描述】:
我正在创建一个自动填充服务在我的 android 密码管理应用程序(使用 java)上。
我已经关注了这个turotial
当我的服务试图获取另一个应用程序的内容时,它似乎无法检测自动填充提示、提示和文本在领域内。
这是我在 AutoFillService 超类的 onFillRequest 方法中的代码:
// 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);
}
然后我用我的 traverseNode 方法遍历节点:
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);
}
}
谢谢你的帮助 !
【问题讨论】:
标签: java android autofill android-autofill-manager password-autofill