title: Android, TelephonyManager, the joys of PhoneStateListener and incoming numbers
body: <p>I've very newly gotten into <code>Android</code> development, and decided that my first conquest on this fresh field would be to grasp how the phone reacted to incoming calls.</p>
  
  <p>A little googling later led me to <a href="http://www.compiletimeerror.com/2013/08/android-call-state-listener-example.html#.Vi3Ren4vfwM">http://www.compiletimeerror.com/2013/08/android-call-state-listener-example.html#.Vi3Ren4vfwM</a> (so my code shares a striking resemblance to his/hers).</p>
  
  <p>My main (and only) activity looks like this:</p>
  
  <pre><code>import android.app.Activity;
  import android.content.Context;
  import android.os.Bundle;
  import android.telephony.PhoneStateListener;
  import android.telephony.TelephonyManager;
  import android.util.Log;
  import android.view.Menu;
  import android.widget.Toast;
  
  public class MainActivity extends Activity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      TelephonyManager TelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
      TelephonyMgr.listen(new TeleListener(),
              PhoneStateListener.LISTEN_CALL_STATE);
  }
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.activity_main, menu);
      return true;
  }
  class TeleListener extends PhoneStateListener {
      public void onCallStateChanged(int state, String incomingNumber) {
          super.onCallStateChanged(state, incomingNumber);
          switch (state) {
              case TelephonyManager.CALL_STATE_IDLE:
                  // CALL_STATE_IDLE;
                  Log.d("MyLittleDebugger", "I'm in " + state + " and the number is " + incomingNumber);
                  Toast.makeText(getApplicationContext(), "CALL_STATE_IDLE",
                          Toast.LENGTH_LONG).show();
                  break;
              case TelephonyManager.CALL_STATE_OFFHOOK:
                  // CALL_STATE_OFFHOOK;
                  Log.d("MyLittleDebugger", "I'm in " + state + " and the number is " + incomingNumber);
                  Toast.makeText(getApplicationContext(), "CALL_STATE_OFFHOOK",
                          Toast.LENGTH_LONG).show();
                  break;
              case TelephonyManager.CALL_STATE_RINGING:
                  // CALL_STATE_RINGING
                  Log.d("MyLittleDebugger", "I'm in " + state + " and the number is " + incomingNumber);
                  Toast.makeText(getApplicationContext(), incomingNumber,
                          Toast.LENGTH_LONG).show();
                  Toast.makeText(getApplicationContext(), "CALL_STATE_RINGING",
                          Toast.LENGTH_LONG).show();
                  break;
              default:
                  break;
          }
      }
  
  }
  }
  </code></pre>
  
  <p>Now, here's where the fun stops. I got the app running on emulator, and used <code>DDMS</code> to spoof a few phone calls to my emulated device to see where the pieces landed.</p>
  
  <p>And surely enough toast popped up and <code>MyLittleDebugger</code> flared up upon state swaps. The listener was working, however no number was ever being shown in my log or my toast.</p>
  
  <p>It was just blank where the number should have been! Not null or anything, no, but blank!</p>
  
  <p>After a little more googling, I realized that my <code>AndroidManifest.xml</code> might be the problem. It is as follows:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.x.xy" &gt;
  
  &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:supportsRtl="true"
      android:theme="@style/AppTheme" &gt;
      &lt;activity android:name=".MainActivity" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p></p>
  
  <p>Now, here's the question: what am I missing?</p>
  
  <p>Clearly, a little fraction of a something has gone wrong somewhere, because I am able to have my <code>TelephonyMgr</code> object <code>.listen()</code> to call states, but I can't get the number to show.</p>
  
  <p><strong>New information:</strong></p>
  
  <p>I've also tried this on my phone, without emulating to the exact same result.</p>