title: How to detect if outgoing phone call is answered in android?
body: <p>Recently, I've been trying to implement a way to detect if an outgoing call is answered or not?</p>
  
  <p>I know that this is an old question in this forum. I've come across the whole useless solutions suggested by developer.</p>
  
  <p><a href="https://stackoverflow.com/questions/13134331/cannot-detect-when-outgoing-call-is-answered-in-android">Tim S.'s answer </a> has come cross using a hidden API that is authorized for only system applications to benefit from <code>PRECISECALL_STATE_ACTIVE</code> leaving no choice to have an explicit state that shows if the call is answered for third party applications. The only available states that are available for 3rd party apps are provided by the telephony manager are <code>CALL_STATE_RINGING</code>, <code>CALL_STATE_OFFHOOK</code>, and <code>CALL_STATE_IDLE</code>, which gives no clue to what i intended to do.</p>
  
  <p>My question is, isn't there any walk around, for example to isolate the audio sources coming from the ear speakers, or away to access the call layout to extract the call timer in real time?? </p>
  
  <p>The code is shown below:</p>
  
  <p><code>class Custom_PhoneState_Listener extends PhoneStateListener{</code></p>
  
  <pre><code>            int state;
              @Override
              public void onCallStateChanged(int state, String incomingNumber) {
                  super.onCallStateChanged(state, incomingNumber);
                  //switch to isolate call states
                  switch(state)
                  {
  
                  case TelephonyManager.CALL_STATE_IDLE:
                      Log.d("call state:","CALL STATE IDLE");
                      state=0;
                      break;
                  case TelephonyManager.CALL_STATE_RINGING:
                      Log.d("call state:","CALL STATE RINGING");
                      state=1;
                      break;
                  case TelephonyManager.CALL_STATE_OFFHOOK:
                      Log.d("call state:","CALL STATE OFFHOCK");
                      state=2;
                      MyFunction(); //the function should be executed once the call is answered
                      break;
                  default: Log.d("call state:","THERE IS NO STATE DETECTED");
                  }
              }`
  </code></pre>