Delete answered incoming call from call log in android
<p>I'm using Broadcast receiver to receive phone_states and checking any call(out/in coming) is being changed it's state to <code>EXTRA_STATE_IDLE</code> and then deleting the call info from call log.
As I know android phone states are:</p>

<ol>
<li><code>EXTRA_STATE_RINGING</code></li>
<li><code>EXTRA_STATE_OFFHOOK</code></li>
<li><code>EXTRA_STATE_IDLE</code></li>
</ol>

<p>Here for incoming calls I know:</p>

<ol>
<li>When incoming call is been received ->
<code>EXTRA_STATE_RINGING</code>=> <code>EXTRA_STATE_OFFHOOK</code>(After Answering call) =>     <code>EXTRA_STATE_IDLE</code>(After End call)</li>
<li>When incoming call is been cut off ->
<code>EXTRA_STATE_RINGING</code>=> <code>EXTRA_STATE_IDLE</code>(After End call)  </li>
</ol>

<p>so, actually I'm clearing call log history when the phone state is in <code>EXTRA_STATE_IDLE</code>. But in this strategy i'm able to clear log history for 2. scenario but unable for 1. scenario.</p>

<p>Here is my code::</p>

<pre><code>String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);

if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)){              
              Toast.makeText(context, "ringing", 20).show();

              SharedPreferences statePreference=context.getApplicationContext().getSharedPreferences("RingCallState", 0);
              SharedPreferences.Editor editor=statePreference.edit();
              editor.putBoolean("State", true);
              editor.commit();

              context.startActivity(i);
          }

          else if (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {

              Toast.makeText(context, "off hook", 20).show();

              SharedPreferences statePreference=context.getApplicationContext().getSharedPreferences("RingCallState", 0);

              Log.d("statePref OFFHOOK", "state :: "+statePreference.getBoolean("State", false));

              if(!statePreference.getBoolean("State", false)) {

                  SharedPreferences out_statePreference=context.getApplicationContext().getSharedPreferences("OutCallState", 0);
                  SharedPreferences.Editor out_editor=out_statePreference.edit();
                  out_editor.putBoolean("OutState", true);
                  out_editor.commit();

              }                 
          }

          else if(state.equals(TelephonyManager.EXTRA_STATE_IDLE)){
              Toast.makeText(context, "idle", 20).show();

              SharedPreferences statePreference=context.getApplicationContext().getSharedPreferences("RingCallState", 0);

              Log.d("statePref IDLE", "state :: "+statePreference.getBoolean("State", false));

              if(statePreference.getBoolean("State", false))
                {                       
                    SharedPreferences.Editor editor=statePreference.edit();
                    editor.putBoolean("State", false);
                    editor.commit();

                    Log.d("in", "in coming :: "+incomingNumber);

                    new Handler().postDelayed(new Runnable() {
                          public void run() {
                              clearLastCallLog(context, incomingNumber);
                          }
                      }, 4000);

                }


                SharedPreferences out_statePreference=context.getApplicationContext().getSharedPreferences("OutCallState", 0);
                if(out_statePreference.getBoolean("OutState", false))
                {
                    SharedPreferences.Editor out_editor=out_statePreference.edit();
                    out_editor.putBoolean("OutState", false);
                    out_editor.commit();

                    Log.d("out", "out going :: "+outgoingNumber);

                    new Handler().postDelayed(new Runnable() {
                          public void run() {
                              clearLastCallLog(context, outgoingNumber);
                          }
                      }, 4000);
                }

          }
</code></pre>

<p>What am I missing... can anyone explain is there any thing to do for handling answered incoming calls??
Any suggestion please... </p>
