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.
{ 12 comments… read them below or add one }
Mr.Varma, I found your blog when I was searching for TelephonyManager tutorial, it is one of the most clean, neat and useful article I have come across.
Kudos to you for taking this initiative of sharing your knowledge.
I have one more question can you suggest me how to pick incoming calls?say I have detected the call.
Wow man! This is so useful for what I’m doing. Thanks a lot buddy!
hi i would like to create a incoming call recorder. The purpose of this is that when you are busy or in a meeting and you can’t answer the call, your phone will just record the call and you can answer it later. Can you give me link or idea where to start because im not yet familiar with android
Nice tutorial. TQ for sharing this…
Hello sir , very nice tutorial..
sir i made a receiver which open a particular activty on dialing of specific number.but i have a problems.
I dont want to press green button to open activity, it should be open autometic when we dial a specific no.
how can capture the dialing no, is there any event which can capture this no…
please hep its very urgent and needfulll.
Thanks..
Hey Mr. Varma, the world needs people like you…People who learn things and share that stuff with others. Thanx, this site is so helpful for me and many others out there, I guess..Yeah buddy, go on..Be blessed!
Hi,
It is simply awesome!!!!!
Thanks for such a wonderful tutorial!!!
Keep The Good Work
How can we detect the incoming call is accepted and the outgoing call has been accepted.
Hi mate,
I’ve got a question to you about catching dial when I press on phone number in e-mail message. I want to swap default client to mine but I’m not sure what intent-filters I should use.Any suggestions ?
Hi ,
Please tell me how to disconnect call by programing .
Thank you, this was very helpful to me.
Thanks a lot. Very neat and accurate.