Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As we learn from the already famous <a href="http://www.codedemigod.com/intercepting-ussd-calls-in-android/">blog post</a> </p> <blockquote> <p>As a start, look at the PhoneUtils class in the Android source code. [...] Specifically, looking at line 217, an intent with the name <strong>“com.android.ussd.IExtendedNetworkService”</strong> is being composed. <strong>So what you need to do is implement your own service that responds to that intent</strong>. The service needs to be implemented according to the IExtendedNetworkService.aidl which is a part of the Android framework.</p> </blockquote> <p>where to start at? the best is to follow this even more famous <a href="http://commandus.com/blog/?p=58">blog post</a></p> <p>First of all, we understand the basics: </p> <ol> <li>We need a service that implements <code>IExtendedNetworkService</code> interface.</li> <li>The service will be aware of the intent <code>"com.android.ussd.IExtendedNetworkService"</code>, so it will have the correspondent intent filter in the app manifest.</li> <li>What we know is that <code>com.android.phone.PhoneUtils</code> will bind to this service. (If you dont know what binding a service is, refer to <a href="http://developer.android.com/guide/components/services.html">here</a>)</li> <li>on Bind we return a binder, which contanins the functions that PhoneUtils will actually call</li> <li>The service has to be be running, so we will have it started when the system reboot. For that we need a broadcast receiver. (If you don't know what is this, and you want to understand all this better, refer to <a href="http://developer.android.com/reference/android/content/BroadcastReceiver.html">here</a>)</li> </ol> <p>Let`s get into it.</p> <p>First, the receiver, this is the easy part. We make a file called BootReceiver.java with this contents. </p> <pre><code>package com.android.ussdcodes; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; public class BootReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub Log.d("USSDService", context.getString(R.string.service_started)); context.startService(new Intent(context,USSDDumbExtendedNetworkService.class)); } } </code></pre> <p>Now, the service itself. I havent tried it myself, but i have read the code <a href="http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.0_r1/com/android/internal/telephony/IExtendedNetworkService.java">here</a> to find the methods explanation, that i've put in comments. Also i edited some stuff. </p> <p>As far as i understand, you will receive the actual text in getUserMessage, there you parse the text, and return what you want to be in the popup. If you dont want popup, return null. So, it is also there where you should do any other stuff with that text.</p> <pre><code>public class USSDDumbExtendedNetworkService extends Service { public static final String TAG = "ExtNetService"; public static CharSequence mRetVal = null; public static boolean mActive = true; private boolean change = false; private String msgUssdRunning = null; private final IExtendedNetworkService.Stub mBinder = new IExtendedNetworkService.Stub() { //Set a MMI/USSD command to ExtendedNetworkService for further process. This should be called when a MMI command is placed from panel. //we don't need it in this case @Override public void setMmiString(String number) throws RemoteException { } //return the specific string which is used to prompt MMI/USSD is running @Override public CharSequence getMmiRunningText() throws RemoteException { return msgUssdRunning; } //Get specific message which should be displayed on pop-up dialog. Parameters: text original MMI/USSD message response from framework Returns: specific user message correspond to text. null stands for no pop-up dialog need to show. @Override public CharSequence getUserMessage(CharSequence text) throws RemoteException { return text; } //Clear pre-set MMI/USSD command. This should be called when user cancel a pre-dialed MMI command. //we don't need it in this case @Override public void clearMmiString() throws RemoteException { } }; @Override public IBinder onBind(Intent intent) { msgUssdRunning = "Some text to show"; return mBinder; } public IBinder asBinder() { return mBinder; } @Override public boolean onUnbind(Intent intent) { return super.onUnbind(intent); }} </code></pre> <p>And the last part, the manifest. You have to register the service, and the broadcastreceiver</p> <pre><code>&lt;receiver android:name="com.android.ussdcodes.BootReceiver"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.BOOT_COMPLETED" /&gt; /intent-filter&gt; &lt;/receiver&gt; &lt;service android:name=".USSDDumbExtendedNetworkService" &gt; &lt;intent-filter android:icon="@drawable/ic_launcher"&gt; &lt;action android:name="com.android.ussd.IExtendedNetworkService" /&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;/intent-filter&gt; &lt;/service&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload