安卓 AccessibilityService 循環查找子控件


/**
     * @param info 當前節點
     * @param matchFlag 需要匹配的文字
     * @param type  操作的類型
     */
    public void recycle(AccessibilityNodeInfo info, String matchFlag, int type) {
        if (info != null) {
            if (info.getChildCount() == 0) {
                CharSequence desrc = info.getContentDescription();
                switch (type) {
                    case ENVELOPE_RETURN://返回
                        if (desrc != null && matchFlag.equals(info.getContentDescription().toString().trim())) {
                            if (info.isCheckable()) {
                                info.performAction(AccessibilityNodeInfo.ACTION_CLICK);
                            } else {
                                performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);
                            }
                        }
                        break;
                }
            } else {
                int size = info.getChildCount();
                for (int i = 0; i < size; i++) {
                    AccessibilityNodeInfo childInfo = info.getChild(i);
                    if (childInfo != null) {
                        Log.e(TAG, "index: " + i + " info" + childInfo.getClassName() + " : " + childInfo.getContentDescription()+" : "+info.getText());
                        recycle(childInfo, matchFlag, type);
                    }
                }
            }
        }
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章