AccessibilityNodeInfo:查看ViewGroup的子级

时间:2018-08-23 03:24:03

标签: android accessibility viewgroup accessibilityservice

我正在构建Android无障碍服务。在各种应用中,我一直在测试一个简单的功能来遍历页面上的节点:

AccessibilityNodeInfo root = getRootInActiveWindow();
Deque<Tuple> deque = new ArrayDeque<>();
deque.add(new Tuple(root, "Root"));
while (!deque.isEmpty()) {
    Tuple det = deque.removeFirst();
    AccessibilityNodeInfo node = (AccessibilityNodeInfo) det.x;
    Log.d("RECURSE", node.getPackageName() + " - " + det.y + ": " + node.getClassName() + " " + node.getText());

    for (int i = 0; i < node.getChildCount(); i++) {
        deque.addLast(new Tuple(node.getChild(i),det.y + ", " + Integer.toString(i)));
    }
 }

但是,在某些应用中,我遇到了这样的死胡同:

  

com.facebook.katana-根,0、4、1:android.view.ViewGroup为空

此ViewGroup没有子级-显然它有子级,并且我无法访问其文本内容。在其他应用中使用ViewPager也会遇到相同的问题。

是否可以将AccessibilityNodeInfo强制转换为ViewGroup并在其中访问其子级,或者以其他方式访问它们?

0 个答案:

没有答案