android - AIDL, bind and unbind IExtendedNetworkService Service -


i use aidl interface iextendednetworkservice ussd code. application work after reboot device. tried bindservice after install app didn't work. problem how way bind service without reboot device . code: interface:

package com.android.internal.telephony;      interface iextendednetworkservice {          void setmmistring(string number);          charsequence getmmirunningtext();          charsequence getusermessage(charsequence text);          void clearmmistring();     } 

service

public class cdussdservice extends service {      private string tag = "thang-nguyen";     private boolean mactive = false;       broadcastreceiver receiver = new broadcastreceiver() {         @override         public void onreceive(context context, intent intent) {             if (intent.getaction().equals(intent.action_insert)) {                 // activity wishes listen ussd returns, activate                 mactive = true;                 log.d(tag, "activate ussd listener");             } else if (intent.getaction().equals(intent.action_delete)) {                 mactive = false;                 log.d(tag, "deactivate ussd listener");             }         }     };      private final iextendednetworkservice.stub mbinder = new iextendednetworkservice.stub() {         public void clearmmistring() throws remoteexception {             log.d(tag, "called clear");         }          public void setmmistring(string number) throws remoteexception {             log.d(tag, "setmmistring:" + number);         }          public charsequence getmmirunningtext() throws remoteexception {             if (mactive == true) {                 return null;             }              return "ussd running";         }          public charsequence getusermessage(charsequence text)                 throws remoteexception {             log.d(tag, "get user message " + text);              if (mactive == false) {                 // listener still inactive, return whatever got                 log.d(tag, "inactive " + text);                 return text;             }              // listener active, broadcast data , suppress             // default behavior              // build data send intent activity, format uri per             // rfc 2396             uri ussddatauri = new uri.builder()                     .scheme(getbasecontext().getstring(r.string.uri_scheme))                     .authority(                             getbasecontext().getstring(r.string.uri_authority))                     .path(getbasecontext().getstring(r.string.uri_path))                     .appendqueryparameter(                             getbasecontext().getstring(r.string.uri_param_name),                             text.tostring()).build();              sendbroadcast(new intent(intent.action_get_content, ussddatauri));              mactive = false;             return null;         }     };      public void oncreate() {         log.i(tag, "called oncreate");     };      @override     public int onstartcommand(intent intent, int flags, int startid) {         log.i(tag, "called onstartcommand");         return super.onstartcommand(intent, flags, startid);     }      @override     public ibinder onbind(intent intent) {         log.i(tag, "called onbind");          // insert/delete intents fired activity         // activate/deactivate listener since service cannot stopped         intentfilter filter = new intentfilter();         filter.addaction(intent.action_insert);         filter.addaction(intent.action_delete);         filter.adddatascheme(getbasecontext().getstring(r.string.uri_scheme));         filter.adddataauthority(                 getbasecontext().getstring(r.string.uri_authority), null);         filter.adddatapath(getbasecontext().getstring(r.string.uri_path),                 patternmatcher.pattern_literal);         registerreceiver(receiver, filter);          return mbinder;     } } 

mainactivity:

public class mainactivity extends activity {      private button btncheckussd;     private context mcontext;     private iextendednetworkservice mservice;     private edittext inputussd;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         mcontext = this;         setcontentview(r.layout.activity_main);         btncheckussd = (button) findviewbyid(r.id.btn_check);         inputussd = (edittext) findviewbyid(r.id.input_ussd);          btncheckussd.setonclicklistener(new onclicklistener() {             @override             public void onclick(view arg0) {                 if (!inputussd.gettext().tostring().isempty()) {                      intent service = new intent(                             "com.android.ussd.iextendednetworkservice");                     bindservice(service, mconnecton, context.bind_auto_create);                      startactivity(new intent("android.intent.action.call", uri                             .parse("tel:" + inputussd.gettext().tostring()                                     + uri.encode("#"))));                 }              }         });       }     serviceconnection mconnecton = new serviceconnection() {          @override         public void onservicedisconnected(componentname name) {             mservice = null;          }          @override         public void onserviceconnected(componentname name, ibinder ibinder) {             mservice = iextendednetworkservice.stub                     .asinterface((ibinder) ibinder);         }     };      protected void ondestroy() {         super.ondestroy();         log.d("thang-nguyen", "ondestroy");         unbindservice(mconnecton);     }    } 

manifest

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="info.example.checkussdcode"     android:versioncode="1"     android:versionname="1.0" >      <uses-sdk         android:minsdkversion="7"         android:targetsdkversion="17" />      <uses-permission android:name="android.permission.read_sms" />     <uses-permission android:name="android.permission.write_sms" />     <uses-permission android:name="android.permission.call_phone" />     <uses-permission android:name="android.permission.receive_boot_completed" />      <application         android:allowbackup="true"         android:icon="@drawable/ic_launcher"         android:label="@string/app_name"         android:theme="@style/apptheme" >         <activity             android:name="info.example.checkussdcode.mainactivity"             android:label="@string/app_name" >             <intent-filter>                 <action android:name="android.intent.action.main" />                  <category android:name="android.intent.category.launcher" />             </intent-filter>         </activity>          <service             android:name="info.example.checkussdcode.service.ussdcodeservice"             android:process=":remote" >             <intent-filter>                 <action android:name="com.android.ussd.iextendednetworkservice" >                 </action>             </intent-filter>         </service>          <receiver android:name="info.example.checkussdcode.rebootreceiver" >             <intent-filter>                 <action android:name="android.intent.action.boot_completed" />             </intent-filter>         </receiver>     </application>  </manifest> 


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -