Search code examples
androidaccessibilityserviceussd

Is there a way to set onclick listener to USSD dialog buttons?


I'm writing an App that interfaces with a payment gateway via an API. Upon initiating a payment transaction, the gateway push/forces a USSD dialog to open on the phone. My goal is to display feedback to the user when the Cancel or Send button is clicked.

I'm looking for something like

List<AccessibilityNodeInfo> list = source.findAccessibilityNodeInfosByText("Send");

for (AccessibilityNodeInfo node : list) {
    node.setOnClickListener(...);
}

Solution

  • There is no way to get click events directly. Using an accessibility service is the right approach, but you'll have to listen for the dialog window events and read what they say. You could get events for clicking the buttons, but I'm not sure it would be worth it since you wouldn't be able to tell what was entered into the session.

    My company Hover has developed an Android SDK which uses accessibility services to run multi-step USSD sessions and have it appear to happen inside your app. You create configurations for USSD services, trigger the session to run from your app and pass in any runtime variables you need. The user never sees the USSD session and when the response is returned your app is notified and you can parse it as you need. It works on Android 4.3 and above.

    The SDK is free to integrate and use until you hit large scale. Please see our docs to get started.

    (Disclosure: I am the CTO of Hover)