当存在取消、发送按钮时,Accessibilityservice 无法从 USSD 响应中关闭 AlertDialog

Accessibilityservice can not close AlertDialog from USSD response when there are CANCEL,SEND buttons

我构建了一个 class a extends AccessibilityService :

...
public void onAccessibilityEvent(AccessibilityEvent event) {
        String text = event.getText().toString();
        if (event.getClassName().equals("android.app.AlertDialog")) {
            performGlobalAction(GLOBAL_ACTION_BACK);
            Toast.makeText(this,
                    text,
                    Toast.LENGTH_SHORT).show();
            G.last_msg = text;
...

当响应只有“确定”按钮时,一切都很好。

但是如果对话框有“CANCEL”、“SEND”按钮和一个 TextBox,我可以获取对话框的内容但不能关闭它。

此外,当此对话框可见时,我尝试单击系统后退按钮,但它没有关闭此对话框。

我只想单击“取消”。怎么样?

找到了

...
public void onAccessibilityEvent(AccessibilityEvent event) {
        String text = event.getText().toString();
        if (event.getClassName().equals("android.app.AlertDialog")) {
            performGlobalAction(GLOBAL_ACTION_BACK);
// start solution
            AccessibilityNodeInfo source = event.getSource(); // source event
            List<AccessibilityNodeInfo> list;
            list = source.findAccessibilityNodeInfosByText("CANCEL"); // find the cancel button
            for (AccessibilityNodeInfo node : list) {
                node.performAction(AccessibilityNodeInfo.ACTION_CLICK); // click it
            }
// end solution
            Toast.makeText(this,
                    text,
                    Toast.LENGTH_SHORT).show();
            G.last_msg = text;
...