How to read USSD Message response in android

Nouman Shah picture Nouman Shah · Apr 28, 2016 · Viewed 7.4k times · Source

i want to store my balance in sqlite database i am successfully dial the USSD

String balance_check="*444";
String encodedHash = Uri.encode("#");
  String ussd = balance_check + encodedHash;
 startActivityForResult(new Intent("android.intent.action.CALL",Uri.parse("tel:" + ussd)), 1);  

Here is onActivityResult function

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 1) {
    if (resultCode == RESULT_OK) {
            String dd = data.toString();
            Log.d("myussdmessage", data.toString());}}

but I cannot get the string exactly how to do it.I want to store the balance form the dialogue to my database.Can any one suggest me how to do it.

Answer

Martin picture Martin · May 19, 2016

You need to build an AccessibilityService in order to do that you need to read the documentation of AccessibilityService in below link https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.html

and also this question helped me

Prevent USSD dialog and read USSD response?