Use accessiblityNodeInfo to get information even when the phone returns, it will receive a ussd response, and it will reject the dialog when it is possible to enter several options.
First of all, in the case of [pohne], the event class name is returned as ussdalertactivty, so I used only a βwarningβ to identify the warning dialog from the ussd response.
public void onAccessibilityEvent(AccessibilityEvent event) { if (event.getPackageName().toString().equals("com.android.phone") && event.getClassName().toString().toLowerCase() .contains("alert")) { AccessibilityNodeInfo source = event.getSource(); if (source != null) { String pcnResponse = fetchResponse(source); } }
Now I have created the fetchResponse function, which will return the answer from pcn as a string and also cancel the dialog, so you need to execute the GlobalAction (GLOBAL_ACTION_BACK) function.
private String fetchResponse(AccessibilityNodeInfo accessibilityNodeInfo) { String fetchedResponse = ""; if (accessibilityNodeInfo != null) { for (int i = 0; i < accessibilityNodeInfo.getChildCount(); i++) { AccessibilityNodeInfo child = accessibilityNodeInfo.getChild(i); if (child != null) { CharSequence text = child.getText(); if (text != null && child.getClassName().equals( Button.class.getName())) { // dismiss dialog by performing action click in normal // cases if (isUSSDFromApp && (text.toString().toLowerCase().equals("ok") || text .toString().toLowerCase() .equals("cancel"))) { child.performAction(AccessibilityNodeInfo.ACTION_CLICK); return fetchedResponse; } } else if (text != null && child.getClassName().equals( TextView.class.getName())) { // response of normal cases if (text.toString().length() > 10) { fetchedResponse = text.toString(); } } else if (child.getClassName().equals( ScrollView.class.getName())) { // when response comes as phone then response can be // retrived from subchild for (int j = 0; j < child.getChildCount(); j++) { AccessibilityNodeInfo subChild = child.getChild(j); CharSequence subText = subChild.getText(); if (subText != null && subChild.getClassName().equals( TextView.class.getName())) { // response of different cases if (subText.toString().length() > 10) { fetchedResponse = subText.toString(); } } else if (subText != null && subChild.getClassName().equals( Button.class.getName())) { // dismiss dialog by performing action click in // different // cases if (isUSSDFromApp && (subText.toString().toLowerCase() .equals("ok") || subText .toString().toLowerCase() .equals("cancel"))) { subChild.performAction(AccessibilityNodeInfo.ACTION_CLICK); return fetchedResponse; } } } } } } } return fetchedResponse; }
Hope this solves the problem regardless of devices.
vishal sharma Apr 26 '16 at 10:02 2016-04-26 10:02
source share