【问题标题】:How can I get the AutoFillHint/HintText/Text from another app structure?如何从另一个应用程序结构中获取自动填充提示/提示文本/文本?
【发布时间】: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


    【解决方案1】:

    我不相信 viewNode 会有任何关联的自动填充提示。相反,它是具有关联提示的子项(即每个可填写字段而不是整个框架)。尝试打印出与每个 childNode 关联的自动填充提示。

    【讨论】:

      猜你喜欢
      • 2020-11-16
      • 2018-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多