ANDROID 自动接听 支持2.3以上版本

最近研究自动接听,发现2.3以上有permission android.permission.MODIFY_PHONE_STATE 的错误,这里给出了一种解决方案,仅供参考。

	/**
	 *  自动接听
	 */
	public void autoAnswerPhone() { 
		try {
			ITelephony itelephony = getITelephony();
			itelephony.silenceRinger(); 
			itelephony.answerRingingCall(); 
		} catch (Exception e) {//2.3以上执行以下代码实现自动接听
			Intent intent = new Intent("android.intent.action.MEDIA_BUTTON");
			KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK);
			intent.putExtra("android.intent.extra.KEY_EVENT",keyEvent);
			context.sendOrderedBroadcast(intent,"android.permission.CALL_PRIVILEGED");
			intent = new Intent("android.intent.action.MEDIA_BUTTON");
			keyEvent = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK);
			intent.putExtra("android.intent.extra.KEY_EVENT",keyEvent);
			context.sendOrderedBroadcast(intent,"android.permission.CALL_PRIVILEGED");
		}
	}



你可能感兴趣的:(android,button,exception,up,phone)