Android - 以编程方式与 USSD 对话框交互

Android - Interacting with USSD dialog programmatically

有没有办法让 Android 应用程序以编程方式与 USSD 对话框交互?该应用程序在根 phone 上运行,不会发布到 google 商店(仅供内部使用)。

我知道我们可以读取 USSD 对话框的响应(使用辅助功能 hack)。但我在这里想要实现的是让 USSD 对话框打开并与之交互,就像普通用户使用软键盘与之交互一样。 谢谢

使用辅助功能服务,我们可以读取 USSD 响应,我们可以与 ussd 对话框交互 box.That 我们可以将值传递给 USSD 对话框。对我来说工作正常。

Tank Prajest tau。 对我来说工作正常。

在 AccessibilityService 实现的 onAccessibilityEvent 函数中

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

在 onAccessibilityEvent 中,您需要先捕获输入字段,然后用您的文本填充它,然后单击 "Send"(如 @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);
    }
}