可能重复:
如何拦截来电android 2.3.x
我正在制作一个覆盖默认电话屏幕的应用程序,它需要与 Android 2.3 及更高版本兼容。
目前我有这个代码:
private void answerCallAidl() throws RemoteException {
// telephonyService.silenceRinger(); -------not work on 2.3
// telephonyService.answerRingingCall(); -------not work on 2.3
Intent headSetUnPluggedintent = new Intent(Intent.ACTION_HEADSET_PLUG);
headSetUnPluggedintent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
headSetUnPluggedintent.putExtra("state", 1); // 0 = unplugged 1 = Headset with microphone 2 = Headset without microphone
headSetUnPluggedintent.putExtra("name", "Headset");
// TODO: Should we require a permission?
sendOrderedBroadcast(headSetUnPluggedintent, null);
Intent buttonDown = new Intent(Intent.ACTION_MEDIA_BUTTON);
buttonDown.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN,
KeyEvent.KEYCODE_HEADSETHOOK));
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));
sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");
}
private void ignoreCallAidl() throws RemoteException {
// telephonyService.silenceRinger(); -------not work on 2.3
// telephonyService.endCall(); -------not work on 2.3
Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);
buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN,
KeyEvent.KEYCODE_HEADSETHOOK));
sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");
}
我的问题是:
- 我无法拒绝来电。
- 它不适用于版本 2.3.5。
- 我希望我的应用程序替换默认的电话屏幕。
我将非常感谢任何帮助。