我想在android 2.3.3中拒绝/接听电话。我尝试使用ITelephony - endcall()
和answerRingingCall()
但没有成功。有什么想法吗?
答案 0 :(得分:2)
如何接听来电:
/**
* Emulates a headset button press to accept the call
*
* @param context
* A context to use
*/
public static void answerPhoneHeadsethook(Context context) {
// Simulate a press of the headset button to pick up the call
// SettingsClass.logMe(tag, "Simulating headset button");
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");
}
就我而言,没有办法拒绝2.3+中的电话(可以用上面的方法接受和拒绝来电,但是然后来电者必须付钱)。
答案 1 :(得分:1)
需要在!!之前发送此意图
Intent headSetUnPluggedintent = new Intent(Intent.ACTION_HEADSET_PLUG);
headSetUnPluggedintent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
headSetUnPluggedintent.putExtra("state", 1);
headSetUnPluggedintent.putExtra("name", "Headset");
// TODO: Should we require a permission?
sendOrderedBroadcast(headSetUnPluggedintent, null);