这段时间做个来电方面的应用,android2.2下面可以直接利用反射机制调获取ITelephony.answerRingingCall(),可以实现接听电话。但android2.3下面这个方法已经被禁用了。
一下为android2.3接听电话解决方法
AudioManager localAudioManager = (AudioManager) paramContext
.getSystemService("audio");
int i2 = 1;
int i1 = 79;
boolean bool1 = localAudioManager.isWiredHeadsetOn();
if (!bool1) {
Intent localIntent3 = new Intent(
"android.intent.action.HEADSET_PLUG");
localIntent3.putExtra("state", 1);
localIntent3.putExtra("microphone", 0);
localIntent3.putExtra("name", "");
paramContext.sendBroadcast(localIntent3);
Intent meida_button = new Intent(
"android.intent.action.MEDIA_BUTTON");
KeyEvent localKeyEvent2 = new KeyEvent(i2, i1);
meida_button.putExtra("android.intent.extra.KEY_EVENT",
localKeyEvent2);
paramContext.sendOrderedBroadcast(meida_button, null);
Intent headset_plug = new Intent(
"android.intent.action.HEADSET_PLUG");
headset_plug.putExtra("state", 0);
headset_plug.putExtra("microphone", 0);
headset_plug.putExtra("name", "");
paramContext.sendBroadcast(headset_plug);
} else {
Intent meida_button = new Intent(
"android.intent.action.MEDIA_BUTTON");
KeyEvent localKeyEvent1 = new KeyEvent(i2, i1);
meida_button.putExtra("android.intent.extra.KEY_EVENT",
localKeyEvent1);
paramContext.sendOrderedBroadcast(meida_button, null);
}