以编程方式接听电话

时间:2012-02-13 11:30:46

标签: android call telephony headset

我制作了这样的代码以便以编程方式回答:

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");
} 

所以...我尝试用界面ITelephony.aidl回答,如果它不能用Hadsethook做它...它几乎适用于所有类型的手机除了Htc Sensation(操作系统:Android 2.3.3) ......任何人都可以帮我解决这个问题!我会感激任何想法!谢谢! )

1 个答案:

答案 0 :(得分:1)

请检查此链接,它会在实际应答前模拟耳机插入。 http://androidbridge.blogspot.com/2011/05/how-to-answer-incoming-call-in-android.html