【问题标题】:I there a way to run an interactive USSD session and hide the session behind a layout file我有一种方法可以运行交互式 USSD 会话并将会话隐藏在布局文件后面
【发布时间】:2021-06-27 14:40:16
【问题描述】:

光环伟人

通过使用辅助功能服务类,我能够成功地作为 USSD 会话运行,例如*796#。

我让服务监听 USSD 响应,因此从我的主要活动中拨打代码后,服务会监听响应,中断对话,输入回复文本。

我这样做是为了自动化服务,例如检查通话时间余额、订阅服务...e.t.c

但是,我想隐藏用户运行的会话,我想通过使用其他应用程序上的绘制功能,以便用户看到的是一个布局文件显示,“正在处理请求...”

如果我运行它而不在其他应用程序上显示布局,它会完美运行!但是,当我调用应用程序来显示布局文件时,应用程序似乎不会与我得到的 USSD 响应进行交互。我想实现类似于 Hover SDK 的功能。

有没有办法处理在后台运行的 USSD?

很抱歉解释冗长,希望它描述得很好。任何帮助是极大的赞赏。如果需要任何澄清,请告诉我。

这是处理 ussd 响应的服务类;

class USSDService : AccessibilityService() {
    @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
    override fun onAccessibilityEvent(event: AccessibilityEvent) {
        try {
            val source = event.source
            /* if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED && !event.getClassName().equals("android.app.AlertDialog")) { // android.app.AlertDialog is the standard but not for all phones  */
            if (event.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED && !event.className.toString()
                    .contains("AlertDialog")
            ) {
                return
            }
            if (event.eventType == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED && (source == null || source.className != "android.widget.TextView")) {
                return
            }
            if (event.eventType == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED && TextUtils.isEmpty(
                    source!!.text
                )
            ) {
                return
            }
            val eventText: List<CharSequence> = if (event.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
                    event.text
                } else {
                    Collections.singletonList(source!!.text)
                }
            val text = processUSSDText(eventText).toString()
            if (TextUtils.isEmpty(text)) return
            val intent = Intent("com.times.ussd.action.REFRESH")
            intent.putExtra("message", text)

            val list: List<AccessibilityNodeInfo> = nodeInfo.findAccessibilityNodeInfosByText("Send")
            for (node in list) {
                if (text.contains("Account Services")) {
                    performGlobalAction(GLOBAL_ACTION_BACK)
                    /** Initiate Draw Over Apps */
                    val nodeInput: AccessibilityNodeInfo = nodeInfo.findFocus(AccessibilityNodeInfo.FOCUS_INPUT)
                    val bundle = Bundle()
                    bundle.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, "1")
                    nodeInput.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, bundle)
                    nodeInput.refresh()
                    Handler().postDelayed({ node.performAction(AccessibilityNodeInfo.ACTION_CLICK) }, 1)
                } else {
                    if (text.contains("Check balance")) {
                        performGlobalAction(GLOBAL_ACTION_BACK)
                        val nodeInput: AccessibilityNodeInfo = nodeInfo.findFocus(AccessibilityNodeInfo.FOCUS_INPUT)
                        val bundle = Bundle()
                        bundle.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, "5")
                        nodeInput.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, bundle)
                        nodeInput.refresh()
                        Handler().postDelayed({ node.performAction(AccessibilityNodeInfo.ACTION_CLICK) }, 1)
                    }
                }
            }
        } catch (e: Exception) {
            val toast = Toast.makeText(this, "ERROR!!\n\n$e", Toast.LENGTH_LONG).show()
        }
    }
}

这是调用ussd代码的代码;

val intent = Intent(Intent.ACTION_CALL).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                                intent.data = Uri.parse("tel:*796%23")
                                intent.putExtra("com.android.phone.force.slot", true)
                                intent.putExtra("com.android.phone.extra.slot", safaricomSim)
                                if (phoneAccountHandleList != null && phoneAccountHandleList.size > safaricomSim) intent.putExtra(
                                    "android.telecom.extra.PHONE_ACCOUNT_HANDLE",
                                    phoneAccountHandleList[safaricomSim]
                                )
                                startActivity(intent)

调用此函数后,我将在后台处理 UDDS 交互,请帮助。提前致谢。

【问题讨论】:

  • 谢谢。我正在寻找将其编码到我的应用程序中。如果这个平台允许的话,我可以为服务付费...

标签: android kotlin background interactive ussd


【解决方案1】:

我和我的团队一直在开发一项名为 AutoUssd (https://autoussd.com) 的服务,您可以使用它来完成这项工作。

SDK 允许您创建隐藏在布局文件后面的多步骤 USSD 会话,并且会话结果通过回调报告给您的应用。

请检查一下,看看它是否符合您的需求。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-07
    • 1970-01-01
    • 1970-01-01
    • 2020-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多