我正在编写一个覆盖默认来电屏幕的应用程序。所以我的应用程序中有一个用于接听电话的按钮。当用户单击按钮时,应用程序将接受该呼叫。到目前为止,我已成功完成此应用程序,可以在Android 2.3.4或更低版本中使用,没有任何问题。但是,当我在android 2.3.5中使用相同的应用程序时,它无法接受该调用。所以我想知道是否有另一种解决方案在android 2.3.5中以编程方式接受调用。提前感谢您提供的任何指导。以下是接听电话的代码。
private static void answerPhoneHeadsethook(Context context) {
// 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));
context.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));
context.sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");
}
答案 0 :(得分:2)
检查这家伙的更新......我想这就是你需要的! http://androidbridge.blogspot.com/2011/05/how-to-answer-incoming-call-in-android.html
答案 1 :(得分:1)
查看http://code.google.com/p/auto-answer/源代码:
AutoAnswer is a very simple android application to answer the phone automatically when it rings. Can be limited to just contacts or starred contacts. Also has a speakerphone option.