Click here to Skip to main content
15,878,809 members
Articles / Mobile Apps / Android
Tip/Trick

Reject and Accept an Incoming Call

Rate me:
Please Sign up or sign in to vote.
5.00/5 (5 votes)
15 Feb 2014CPOL 61.7K   11   8
This article helps you to reject and accept an incoming call for your Android device with functions.

Introduction

This article helps you to reject and accept an incoming call for your Android device with functions.

Using the code

You can use the rejectCall and acceptCall functions to automate your response for specific numbers or groups. The number coming from an incoming call can be caught with a phonestate listener, then the code can reject or you can accept incoming calls depend on this phone number.

For example, you can reject an incoming call with an unknown number or you can accept an incoming call coming from your favourite contacts automatically.

The code snippets show how to reject and accept an incoming call.

Reject an incoming call:

Java
private void rejectCall(Context context) 
{

Intent buttonDown = new Intent(Intent.ACTION_MEDIA_BUTTON); buttonDown.putExtra(Intent.EXTRA_KEY_EVENT,
new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK));
context.sendOrderedBroadcast(buttonDown, "android.permission.CALL_PRIVILEGED");}

Accept an incoming call:

Java
public static void acceptCall(Context context) 
{
    Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);
    buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, 
      new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));
    context.sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");
} 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Turkey Turkey
Phd. Yildirim Kocdag is a Computer Engineer.

Programming Languages
Android, Objective-c, c#, vb.net, asp.net, javascript, TSQL.

Computer Science
DataMining, Compilers, Expert Systems, Digital Image Processing, AI and Extreme Programming.

ykocdag@yahoo.com

http://www.linkedin.com/profile/view?id=223886830

Comments and Discussions

 
QuestionPROBLEM ON HTC Pin
Rufatet9-Mar-14 6:37
Rufatet9-Mar-14 6:37 
Questionheadset hook Pin
waldleben20-Feb-14 0:25
waldleben20-Feb-14 0:25 
AnswerRe: headset hook Pin
Yildirim Kocdag20-Feb-14 9:16
Yildirim Kocdag20-Feb-14 9:16 
QuestionNo difference between your Accept and Reject code Pin
Alex_II14-Feb-14 17:11
Alex_II14-Feb-14 17:11 
AnswerRe: No difference between your Accept and Reject code Pin
Yildirim Kocdag15-Feb-14 8:49
Yildirim Kocdag15-Feb-14 8:49 
AnswerRe: No difference between your Accept and Reject code Pin
BladedGhost19-Feb-14 23:27
professionalBladedGhost19-Feb-14 23:27 
GeneralRe: No difference between your Accept and Reject code Pin
Yildirim Kocdag20-Feb-14 9:18
Yildirim Kocdag20-Feb-14 9:18 
GeneralRe: No difference between your Accept and Reject code Pin
BladedGhost20-Feb-14 18:41
professionalBladedGhost20-Feb-14 18:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.