title: Detect the end of an answered incoming call by user in android? (not declined)
body: <p>In my android application, I have created a <code>BroadcastReceiver</code> that detects incoming call; my code is running very well.  If there is an incoming call (<code>EXTRA_STATE_RINGING</code>), I can see my incommingNumber in the logcat, also when the user answered the call (<code>EXTRA_STATE_OFFHOOK</code>)</p>
  
  <ul>
  <li>I used <code>shared preferences</code> to store incoming number (String) in ringing state , then get it in Off HOOK state.</li>
  </ul>
  
  <p>This is my code, it works perfectly:</p>
  
  <pre><code> public class IncomingCallReceiver extends BroadcastReceiver {
  
      @Override
      public void onReceive(Context context, Intent intent) {
  
             String incomingNumber = null ;
            if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_RINGING)) 
            {
              // Ringing state
              // Phone number 
                incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
  
                Log.i("test2", incomingNumber);
  
                SharedPreferences myPrefs = context.getSharedPreferences("myPrefs",Context.MODE_WORLD_WRITEABLE);
                SharedPreferences.Editor prefsEditor = myPrefs.edit();
                prefsEditor.putString("Incomingnumber", incomingNumber);
                //Not forgot to commit.
                prefsEditor.commit();
  
  
            } 
  
            else if  (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) 
            {
                //get the incoming number 
                SharedPreferences myPrefs = context.getSharedPreferences("myPrefs",Context.MODE_WORLD_READABLE);
                String incomNumber = myPrefs.getString("Incomingnumber", incomingNumber);
  
                // This code will execute when the call is answered
  
                Log.i("test2", incomNumber);
                Toast.makeText(context,incomNumber, Toast.LENGTH_LONG).show();
  
            }
  </code></pre>
  
  <p><strong>BUT :</strong> 
  My problem that my code can display a toast when the user just <code>Accept</code> the incoming call.</p>
  
  <p>So, I need to know <strong>how I can detect the end of an answered the incoming call</strong> to do something else (display an alert dialog or launch an activity)</p>