Click here to Skip to main content
11,712,727 members (79,496 online)
Click here to Skip to main content

Reject and Accept an Incoming Call

, 15 Feb 2014 CPOL 28.1K 10
Rate this:
Please Sign up or sign in to vote.
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:

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:

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)

Share

About the Author

Yildirim Kocdag
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

You may also be interested in...

Comments and Discussions

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

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150819.1 | Last Updated 15 Feb 2014
Article Copyright 2013 by Yildirim Kocdag
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid