How do I get state of a outgoing call in android phone?

Ken picture Ken · May 20, 2010 · Viewed 15.9k times · Source

I noticed in the class TelephonyManager there are CALL_STATE_IDLE, CALL_STATE_OFFHOOK and CALL_STATE_RINGING. They seem to be used for incoming calls.

What I actually want to do is to be notified when an outgoing call is made, is received, or timed out. How to do that?

Answer

htafoya picture htafoya · Jul 25, 2012

I don't know if you can detect a timed call, but differentiate when the call started is possible.

You can do it like this, in the CALL_STATE_IDLE:

Uri allCalls = Uri.parse("content://call_log/calls");
String lastMinute = String.valueOf(new Date().getTime() - DAY_IN_MILISECONDS); 
//before the call started
Cursor c = app.getContentResolver().query(allCalls, null, Calls.DATE + " > " 
           + lastMinute, null, Calls.DATE + " desc");
c.moveToFirst();

if (c.getCount() > 0) {
    int duration = Integer.parseInt(c.getString(c.getColumnIndex(Calls.DURATION)));
}

if duration is > 0 then then it call was answered.

Obviously there are other flags that you should use to determine that CALL_STATE_IDLE is called after a call was made.

Hope that helps and put you in the corret way for what you are trying to do.