detects and clicks a "Cancel" button in a dialog box

Viewed 18

I am trying to auto click on a "Cancel" button in an application uninstall dialog box, but it is not working. In fact, nothing happens at all. No more which way to go.

public static final String UNINSTALLATION_PACKAGE_NAME = "com.android.packageinstaller";
@Override
public void onAccessibilityEvent(final AccessibilityEvent event) {
 if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
 if (event.getPackageName() != null && UNINSTALLATION_PACKAGE_NAME.equals(event.getPackageName().toString())) {
 closeDialog(event);
 }
 }
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void closeDialog(AccessibilityEvent event) {
 AccessibilityNodeInfo nodeInfo = event.getSource();
 if (nodeInfo == null) {
 return;
 }
 List<AccessibilityNodeInfo> list = nodeInfo.findAccessibilityNodeInfosByText("Cancel");
 for (AccessibilityNodeInfo node : list) {
 node.performAction(AccessibilityNodeInfo.ACTION_CLICK);
 }
}
0 Answers
Related