如何使用 Android 中的 AccessibilityEvent 获取另一个 App 特定屏幕上所有 textview 的文本、resourceid?

How to use AccessibilityEvent in Android to get the text, resourceid of all textviews on a particular screen of another App?

我创建了一个扩展 AccessibilityService 的 class。 'onAccessibilityEvent' 方法给出了一个可访问性事件。如何使用它遍历屏幕上的所有 TextView 并仅获取文本数据?另外,如何读取 webview 的 html 数据?

@Override
    public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) {

}

Android developer site 有一个很好的例子。你可以试试:

AccessibilityNodeInfo source = event.getSource();
if (source == null) {
    return;
}

// Grab the parent of the view that fired the event.
AccessibilityNodeInfo rowNode = getListItemNodeInfo(source);
if (rowNode == null) {
    return;
}

for (int i = 0; i < rowNode.getChildCount(); i++) {
    AccessibilityNodeInfo node = rowNode.getChild(i);
    if ("TextView".eaquals(node.getClassName())) {
         Log.i("text", node.getText());
    }
}