Android-以编程方式与USSD对话框交互 [英] Android - Interacting with USSD dialog programmatically
问题描述
Android应用程序是否可以通过程序与USSD对话框进行交互?该应用程序可在有根电话上运行,并且不会发布到Google商店中(仅供内部使用).
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).
我知道我们可以读取USSD对话框的响应(使用可访问性技巧).但是,我要在这里实现的是让USSD对话框打开并与之交互,就像普通用户使用软键盘与之交互一样. 谢谢.
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.
推荐答案
在onAccessibilityEvent中,您需要先捕获输入字段,然后用文本填充它,然后单击发送"(如@lewil所述) ngah)
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);
}
}
这篇关于Android-以编程方式与USSD对话框交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!