Android - Interacting with USSD dialog programmatically

非 Y 不嫁゛ 提交于 2019-11-26 23:33:34

问题


Is there a way for an Android app to interact with the USSD dialog programmatically? The app runs on rooted phone and will not be published to google store (only for internal usage).

I'm aware that we can read the response of an USSD dialog (using accessibility hack). But what I'm trying to achieve here is to let the USSD dialog open and interact with it just like a normal user interact with it using the soft keyboard. Thanks.


回答1:


In the onAccessibilityEvent, you will need to first capture the input field, then fill it with your text, then click the "Send" (as explained by @lewil ngah)

AccessibilityNodeInfo source = event.getSource();
if (source != null) {
    //capture the EditText simply by using FOCUS_INPUT (since the EditText has the focus), you can probably find it with the viewId input_field
    AccessibilityNodeInfo inputNode = source.findFocus(AccessibilityNodeInfo.FOCUS_INPUT);
    if (inputNode != null) {//prepare you text then fill it using ACTION_SET_TEXT
        Bundle arguments = new Bundle();
        arguments.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE,"text to enter");
        inputNode.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, arguments);
    }
    //"Click" the Send button
    List<AccessibilityNodeInfo> list = source.findAccessibilityNodeInfosByText("Send");
    for (AccessibilityNodeInfo node : list) {
        node.performAction(AccessibilityNodeInfo.ACTION_CLICK);
    }
}



回答2:


Tank Prajest tau. For me is working fine.

in onAccessibilityEvent function, of AccessibilityService implementation

AccessibilityNodeInfo nodeInfo = event.getSource();
    List<AccessibilityNodeInfo> list = nodeInfo.findAccessibilityNodeInfosByText("Send");
    for (AccessibilityNodeInfo node : list) {
        node.performAction(AccessibilityNodeInfo.ACTION_CLICK);
    }



回答3:


Using Accessibility service we can read the USSD responce and we can able to interact with ussd dialog box.That we can able to pass the value to USSD dialog box. For me is working fine.



来源:https://stackoverflow.com/questions/35793378/android-interacting-with-ussd-dialog-programmatically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!