title: How to detect when phone is answered or rejected
body: <p>I managed to prepare an activity when the phone is ringing. Now I need to know how to cancel this activity, when I answer the phone or I reject the call.Do I call <code>EXTRA_STATE_IDLE</code> or <code>EXTRA_STATE_OFFHOOK</code> ?</p>
  
  <p>Any ideas?</p>
  
  <p><strong>Manifest</strong></p>
  
  <pre><code>    &lt;receiver android:name=".IncomingBroadcastReceiver"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.PHONE_STATE" /&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
  </code></pre>
  
  <p><strong>IncomingBroadcastReceiver java Class</strong></p>
  
  <pre><code>public class IncomingBroadcastReceiver extends BroadcastReceiver {
      @Override
      public void onReceive(Context context, Intent intent) {
          String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
          // If an incoming call arrives
          if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) { //Did my work }
  </code></pre>