user976143
user976143

Reputation: 1

Programmatically answer the call

I made such code for answering programmatically:

try {
   telephonyService.answerRingingCall();            
}
catch (Exception exx) {
     answerPhoneHeadsethook();
}

private void answerPhoneHeadsethook() {
    // Simulate a press of the headset button to pick up the call
    Intent buttonDown = new Intent(Intent.ACTION_MEDIA_BUTTON);
    buttonDown.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK));
    activity.sendOrderedBroadcast(buttonDown, "android.permission.CALL_PRIVILEGED");

    // froyo and beyond trigger on buttonUp instead of buttonDown
    Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);
    buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));
    activity.sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");
} 

So...i try to answer with interface ITelephony.aidl, and if it cant, make it with Hadsethook...it working almost on all types of mobile-phones except Htc Sensation (OS: Android 2.3.3)...Can anyone help me to solve this problem! I`ll appreciate any ideas! Thank you! )

Upvotes: 0

Views: 1061

Answers (1)

saeed khalafinejad
saeed khalafinejad

Reputation: 1133

Please check this link, it simulate headset plugged-in before actual answering. http://androidbridge.blogspot.com/2011/05/how-to-answer-incoming-call-in-android.html

Upvotes: 1

Related Questions