Java tutorial
//package com.java2s; import android.accessibilityservice.AccessibilityService; import android.view.accessibility.AccessibilityNodeInfo; import java.util.List; public class Main { public static void findTextAndClick(AccessibilityService accessibilityService, String text) { AccessibilityNodeInfo accessibilityNodeInfo = accessibilityService.getRootInActiveWindow(); if (accessibilityNodeInfo == null) { return; } List<AccessibilityNodeInfo> nodeInfoList = accessibilityNodeInfo.findAccessibilityNodeInfosByText(text); if (nodeInfoList != null && !nodeInfoList.isEmpty()) { for (AccessibilityNodeInfo nodeInfo : nodeInfoList) { if (nodeInfo != null && (text.equals(nodeInfo.getText()) || text.equals(nodeInfo.getContentDescription()))) { performClick(nodeInfo); break; } } } } public static void performClick(AccessibilityNodeInfo nodeInfo) { if (nodeInfo == null) { return; } if (nodeInfo.isClickable()) { nodeInfo.performAction(AccessibilityNodeInfo.ACTION_CLICK); } else { performClick(nodeInfo.getParent()); } } }