java - android read USSD response -


i'm trying read ussd response sim balance amount etc, , i'm having issues, have been reading many questions related on stackoverflow, nothing has worked far. except came close: prevent ussd dialog , read ussd response?. @henboy331

but i'm still having issues it. broadcast receiver doesn't called too. i'm using 4.4.2

but shows nothing. can't seem parse message , balance.

i have mainactivity make phone call, receiveractivity implement broadcast receiver, ussdservice class ussd response.

mainactivity.java

public class mainactivity extends appcompatactivity {      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          startservice(new intent(this, ussdservice.class));         dailnumber("100");      }      private void dailnumber(string code) {         string ussdcode = "*" + code + uri.encode("#");         startactivity(new intent("android.intent.action.call", uri.parse("tel:" + ussdcode)));     } } 

recieveractivity.java

public class recieveractivity extends appcompatactivity {      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          intentfilter filter = new intentfilter("com.times.ussd.action.refresh");         this.registerreceiver(new receiver(), filter);     }      public class receiver extends broadcastreceiver {          private string tag = "xxxx";          @override         public void onreceive(context context, intent intent) {              string message = intent.getstringextra("message");             log.i(tag, "got message: " + message);          }      }  } 

ussdservice.java

public class ussdservice extends accessibilityservice {          public string tag = "xxxx";          @override         public void onaccessibilityevent(accessibilityevent event) {             log.d(tag, "onaccessibilityevent");              accessibilitynodeinfo source = event.getsource();         /* if (event.geteventtype() == accessibilityevent.type_window_state_changed && !event.getclassname().equals("android.app.alertdialog")) { // android.app.alertdialog standard not phones  */             if (event.geteventtype() == accessibilityevent.type_window_state_changed && !string.valueof(event.getclassname()).contains("alertdialog")) {                 return;             }             if(event.geteventtype() == accessibilityevent.type_window_content_changed && (source == null || !source.getclassname().equals("android.widget.textview"))) {                 return;             }             if(event.geteventtype() == accessibilityevent.type_window_content_changed && textutils.isempty(source.gettext())) {                 return;             }              list<charsequence> eventtext;              if(event.geteventtype() == accessibilityevent.type_window_state_changed) {                 eventtext = event.gettext();             } else {                 eventtext = collections.singletonlist(source.gettext());             }              string text = processussdtext(eventtext);              if( textutils.isempty(text) ) return;              // close dialog             performglobalaction(global_action_back); // works on 4.1+              log.d(tag, text);              // handle ussd response here             intent intent = new intent("com.times.ussd.action.refresh");             intent.putextra("message", text);             sendbroadcast(intent);          }          private string processussdtext(list<charsequence> eventtext) {             (charsequence s : eventtext) {                 string text = string.valueof(s);                 // return text if text expected ussd response                 if( true ) {                     return text;                 }             }             return null;         }          @override         public void oninterrupt() {         }          @override         protected void onserviceconnected() {             super.onserviceconnected();             log.d(tag, "onserviceconnected");             accessibilityserviceinfo info = new accessibilityserviceinfo();             info.flags = accessibilityserviceinfo.default;             info.packagenames = new string[]{"com.android.phone"};             info.eventtypes = accessibilityevent.type_window_state_changed | accessibilityevent.type_window_content_changed;             info.feedbacktype = accessibilityserviceinfo.feedback_generic;             setserviceinfo(info);         }     } 

androidmanifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.dialussd">      <uses-permission android:name="android.permission.call_phone" />     <uses-permission android:name="android.permission.receive_boot_completed" />       <application         android:allowbackup="true"         android:icon="@mipmap/ic_launcher"         android:label="@string/app_name"         android:supportsrtl="true"         android:theme="@style/apptheme">         <activity android:name=".mainactivity">             <intent-filter>                 <action android:name="android.intent.action.main" />                  <category android:name="android.intent.category.launcher" />             </intent-filter>         </activity>           <service             android:name=".services.ussdservice"             android:enabled="true"             android:exported="true"             android:permission="android.permission.bind_accessibility_service">             <intent-filter>                 <action android:name="android.accessibilityservice.accessibilityservice" />             </intent-filter>             <meta-data android:name="android.accessibilityservice"                 android:resource="@xml/config_service" />         </service>          <receiver android:name=".recieveractivity$receiver" >             <intent-filter>                 <action android:name="android.intent.action.boot_completed" />             </intent-filter>         </receiver>        </application>  </manifest> 

please, there way i'm implementing wrongly, or perhaps there new way ussd responses works?

after launch, change settings manually

setting->accessibility setting -> can see option 'your app name'. turn on. (this has done part of application flow(not manual))


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -