Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 590
Ken Avatar asked May 20 '10 08:05

Ken


People also ask

How do I bar outgoing calls?

Navigate to Restrictions -> Phone. Under Calls, find the Outgoing calls option and click on Restrict to block outgoing calls on Android devices. Next, Save and Publish the restrictions profile. It is recommended to test the profile on a test device before associating it with your production environment.

How do I find incoming and outgoing calls on Android?

You need a BroadcastReceiver for ACTION_PHONE_STATE_CHANGED This will call your received whenever the phone-state changes from idle,ringing,offhook so from the previous value and the new value you can detect if this is an incoming / outgoing call.


1 Answers

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.

like image 169
htafoya Avatar answered Nov 08 '22 03:11

htafoya