Android BroadcastReceiver tutorial: detect outgoing phone call event

Tutorial shows how to catch outgoing phone call event in Android application (including called phone number information).

This basically consists of catching an Intent that is sent by Android OS while call was initiated. So the BroadcastReceiver is required. Steps to build it are as follows:

1. Create OutgoingCallBroadcastReceiver

This is a BroadcastReceiver that will catch and handle incoming intents. Full implementation is short:

public class OutgoingCallReceiver extends BroadcastReceiver {
	@Override
	public void onReceive(Context context, Intent intent) {
		Log.d(OutgoingCallReceiver.class.getSimpleName(), intent.toString());
		Toast.makeText(context, "Outgoing call catched!", Toast.LENGTH_LONG).show();
		//TODO: Handle outgoing call event here
	}
}

2. Register OutgoingCallBroadcastReceiver in AndroidManifest.xml

Newly created BroadcastReceiver will wait for android.intent.action.NEW_OUTGOING_CALL intent actions. In order to direct such intents to Receiver add this code to AndroidManifest.xml:

<receiver android:name=".OutgoingCallReceiver" >
	<intent-filter>
		<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
	</intent-filter>
</receiver>

3. Add permission in AndroidManifest.xml

Your application will now need to request for PROCESS_OUTGOING_CALLS permission. Add that request to AndroidManifest.xml:

<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>

4. Get called phone number (optional)

Intent that I just catched has Extra with phone number, so if you need it, just get that String Extra from intent with:

String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

Just add the foregoing line to the OnReceive method:

@Override
public void onReceive(Context context, Intent intent) {
	String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
	Log.d(OutgoingCallReceiver.class.getSimpleName(), intent.toString() + ", call to: " + phoneNumber);
	Toast.makeText(context, "Outgoing call catched: " + phoneNumber, Toast.LENGTH_LONG).show();
	//TODO: Handle outgoing call event here
}

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!

36 thoughts on “Android BroadcastReceiver tutorial: detect outgoing phone call event

  1. That’s exactly what i need, thank you, but can i make a question? ( i’m new in android programming … ) how can i make this run on my phone? i mean, whit “standard” application i create a new android project in eclipse, i code a “main activity” that extends activity and then i run and close it. With a broadcast receiver instead? i tried the same way, but no toast appear when i make a call, what i’m missing?

    Thank you for the eventual answer and sorry for my horrible english :P !

    1. Yes – You shopuld do exactly what you described. Leave your activity. don’t delete it. just add another class – the BroadcastReceiver.

      Remember also to edit AndroidManifest.xml to register Broadcast receiver and declare required permissions.

      And that’s all I can do for you now – Since you are asking for Android basics, please find some starter tutorials (search for ‘Best Android tutorials’ post on my blog)

      1. Oh, i were missing the activity i didn’t createt this time … thank you!

    1. Then you have to pass service reference as a dependency to this BroadcastReceiver

    1. there should be another kind of intent idicating call end. I did not need to use it so I am not sure – google for it :)

  2. I am working on Audio app. I want to pause music when phone rings or user dials a number, and resume when call ends.. How can I do it?

    1. there should be another kind of intent idicating call end. I did not need to use it so I am not sure – google for it :)

      1. first, thanks for your reply,
        my question is: i want to know when will the call finish to do something. your help is highly appreciated.

  3. i m using dis code…no i am able to get outgoing number..but problem is that when i m making a new outgoing call it cut automatically…

      1. if(intent.getAction().equals(“android.intent.action.NEW_OUTGOING_CALL”))
        {
        number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        smsManager.sendTextMessage(s, null, “outgoing call to=”+number, null, null);
        System.out.println(“outgoing call to”+ number);

        }
        i am doing like this

  4. This code does not work. Tested in Nexus 5, Nexus 6. I am just able to make outgoing calls. I set the debug point on OutgoingCallReceiver#onReceive(..) method to check, but the method is not even invoked. I set the permission to “android.permission.PROCESS_OUTGOING_CALLS”, set the intent filter to “android.intent.action.NEW_OUTGOING_CALL”, none of those works. Outgoing call is allowed.

    It is not working mate.

    Thanks.

    1. Had the same problem, Solved this by adding the permission test like this:
      if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {

      }

  5. hello
    i want to detect each n every incoming n outgoing details from my phone, for that m able to detect the notifications from the “notificaiton bar” of my phone i.e. whatever comes in my “notification bar” m able to detect that data but if its not there in notification bar m not able to detect it.
    plz help me to find the solution…
    it should record each n every incoming n outgoing notification (calls, SMS, whatsapp, Facebook and other applications data).

Give Your feedback: