0

I am able to detect which URL is being loaded in Chrome Custom Tab with help of accessibility service, and now i want to find id of back button so that i can close the tab if the url is in the block list, following is the code for click action:

List<AccessibilityNodeInfo> list = nodeInfo.
findAccessibilityNodeInfosByViewId("com.android.chrome:"id for back button"");
        for (AccessibilityNodeInfo node : list) {
            Log.i(TAG, "ACC::onAccessibilityEvent: back_button " + node);
            node.performAction(AccessibilityNodeInfo.ACTION_CLICK);
        }
Max
  • 510
  • 5
  • 16

1 Answers1

0

Everything about your code is reasonably accurate. The problem with the findAccessibilityNodeInfosByViewId function is not all views have a viewId. You're going to have to do your own crawl through the view hierarchy in order to accomplish this, and look for properties other than view ID.

If you want to see what the viewID is, you should use the Android Device Monitor Hierarchy Dump to get access to this, and also help understand other properties you might look at to see what else you can find that might be more consistent and not rely on an ID.

enter image description here

Here we see a typical screen dump from Android Device Monitor. As you can see the view ID for the highlighted view shows up in the information below IF it has one. Note also, that multiple views can share this ID! It is the ViewIdResourceName, NOT a unique ID.

MobA11y
  • 18,425
  • 3
  • 49
  • 76