Detecting incoming and outgoing calls in Android

Download source code of this article

In one of my project, I wanted to detect incoming and outgoing calls. I used BroadcastReceiver with action android.intent.action.NEW_OUTGOING_CALL and android.intent.action.PHONE_STATE.

The android.intent.action.NEW_OUTGOING_CALL will be broadcasted when an outgoing call is initiated. The receiving intent will have an extra string variable Intent.EXTRA_PHONE_NUMBER which contains the outgoing number. This requires the permission android.permission.PROCESS_OUTGOING_CALLS.

To detect the incoming call, we register a BroadcastReceiver for the action android.intent.action.PHONE_STATE. This will be broadcasted when there is a change in phone state. The receiving intent will have an extra string variable TelephonyManager.EXTRA_STATE which describes the phone state. If this state is TelephonyManager.EXTRA_STATE_RINGING then there will be another extra string variable TelephonyManager.EXTRA_INCOMING_NUMBER. This variable contains the incoming phone number. Note that this variable will not be present when the state is not TelephonyManager.EXTRA_STATE_RINGING.

The sample application is a simple one just for demonstration. The application registers for these actions and when the calls are detected it just displays a toast.


Add yours →

  1. Hello Krishna,

    I have a broadcast receiver that listens to Phone State. I am trying to get the last call log entry when the phone state is idle but it always gives me the previous entry.

    Seems the call log is updated later in the change. I tried setting the priority as 0 so that it is the last receiver.

    Something similar to

    Any idea?

  2. Your code for outgoing call is not working .Its giving null value

  3. Your code for getting outgoing call is not working.It returns null instead of some number.

  4. I am searching for 2 things
    1. Auto Answer the call, then play a Pre-defined Audio file to the Record the cal-lee voice as Audio file.
    2. Auto Answer the call and play Pre-defined Audio files based on the cal-lee Touch tones/DTMF tones.

    Can you help me? Thanks in Advance.

Leave a Reply