簡體   English   中英

如何從另一個應用程序結構中獲取 AutoFillHint/HintText/Text?

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

我正在我的 android 密碼管理應用程序(使用 java)上創建一個AutoFillService

我已經關注了這個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);
    }
}

謝謝你的幫助 !

我不相信viewNode會有任何關聯的自動填充提示。 相反,它是具有關聯提示的子項(即每個可填寫字段而不是整個框架)。 嘗試打印出與每個childNode關聯的自動填充提示。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM