title: Incoming call broadcast receiver not working
body: <p>I'm facing a weird problem. I'm unable to catch incoming calls using broadcast receiver. I've double and triple checked my manifest file for necessary permissions. Everything seems okay but don't know why, the receiver is not working. Can anybody please suggest the reason for this? Any help would be appreciated!
  Here is my skeleton code:</p>
  
  <p>Main:</p>
  
  <pre><code>package com.calllistener;
  
  import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.telephony.PhoneStateListener;
  import android.telephony.TelephonyManager;
  
  public class MainActivity extends BroadcastReceiver {
  
      @Override
      public void onReceive(Context context, Intent intent) {
          MyPhoneStateListener phoneListener=new MyPhoneStateListener(context);
          TelephonyManager telephony = (TelephonyManager) 
          context.getSystemService(Context.TELEPHONY_SERVICE);
          telephony.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);       
      }
  }
  </code></pre>
  
  <p><code>MyPhoneStateListener</code> Class:</p>
  
  <pre><code>package com.calllistener;
  
  import android.content.Context;
  import android.telephony.PhoneStateListener;
  import android.telephony.TelephonyManager;
  import android.util.Log;
  import android.widget.Toast;
  
  public class MyPhoneStateListener extends PhoneStateListener {
      Context ctx;
      public MyPhoneStateListener (Context ctx) {
          super();
          this.ctx=ctx;
      }
      public void onCallStateChanged(int state, String incomingNumber) {
          switch (state) {
          case TelephonyManager.CALL_STATE_IDLE:
              Log.d("DEBUG", "IDLE");
              break;
          case TelephonyManager.CALL_STATE_OFFHOOK:
              Log.d("DEBUG", "OFFHOOK");
              break;
          case TelephonyManager.CALL_STATE_RINGING:
              Toast.makeText(ctx, "Ringing", Toast.LENGTH_LONG).show();
              Log.d("DEBUG", "RINGING");
              break;
          }
      }
  }
  </code></pre>
  
  <p>Manifest:  </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.calllistener"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="14"
          android:targetSdkVersion="17" /&gt;
      &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="Call listener" &gt;
          &lt;receiver android:name="MainActivity" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.PHONE_STATE" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>