坚持开发交互式 USSD 应用程序

Stuck in developing an interactive USSD app

伟大的人晕?

我正在使用下面的代码来获取、关闭和烘烤 USSD 响应消息,但是,我想与包含菜单或选项的 ussd 响应进行交互,

例如,在USSD的编辑文本中回复一个,然后点击发送按钮。

我该怎么做。如果您有一些参考代码、示例,或者您可以指出正确的方向,我将不胜感激。

提前感谢任何帮助。

谢谢,注意安全。

class USSDService : AccessibilityService() {

@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
override fun onAccessibilityEvent(event: AccessibilityEvent?) {
    val ussdResponse = event!!.text.toString().replace("[", "").replace("]", "")
    if( TextUtils.isEmpty(ussdResponse) ) return;
    if (event.className == "android.app.AlertDialog") {
        performGlobalAction(GLOBAL_ACTION_BACK)
        val intent = Intent("com.times.ussd.action.REFRESH")
        intent.putExtra("message", ussdResponse)

        val nodeInfo = event.source
        val list: List<AccessibilityNodeInfo> = nodeInfo.findAccessibilityNodeInfosByText("Send")
        for (node in list) {

            if (ussdResponse.contains("Select User")){
                /** I would like to perform the setting of text and replying back here... */
            }
        }



        Toast.makeText(this, ussdResponse, Toast.LENGTH_LONG).show()
        // 
    }
}

override fun onInterrupt() {
    TODO("Not yet implemented")
}

override fun onServiceConnected() {
    super.onServiceConnected()
    val info = AccessibilityServiceInfo()
    info.flags = AccessibilityServiceInfo.DEFAULT
    info.packageNames = arrayOf("com.android.phone")
    info.eventTypes = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
    info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC
    serviceInfo = info
}

}

/** 我找到了以下代码; */

val inputNode = source.findFocus(AccessibilityNodeInfo.FOCUS_INPUT)
val arguments = Bundle() 

arguments.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, "2")

inputNode.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, arguments)
for (node in list) {                                        
      node.performAction(AccessibilityNodeInfo.ACTION_CLICK)
}

本应回复 6 但 returns 为空。 输入为空出现异常

任何人看到我哪里做错了什么!

我注意到 NOT Android 支持低于 API 5,但在 API 6 及更高版本中运行良好。