嘿,我想在通话过程中按 1 或 2。例如,当您致电呼叫中心并希望按 1 键去销售部门而不用手单击此号码时,但我想在通话期间单击它有问题。
现在我可以调用按键并处理呼叫事件,但它不起作用。
PhoneStateListener myCallListener = new PhoneStateListener(){
@Override
public void onCallStateChanged(int state, String incomingNumber) {
// the variable incomingNumber holds the number calling.
// the state variable holds the state of the phone (Ringing, Idle ...)
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
Log.e("Incoming_call", incomingNumber+" is calling me ...");
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
KeyEvent eventDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_1);
dispatchKeyEvent(eventDown);
// your logic here, right now the incoming caller is logged.
Log.e("Out Call", incomingNumber+" is calling me ...");
break;
default:
break;
}
super.onCallStateChanged(state, incomingNumber);
}
};
TelephonyManager phoneManager = (TelephonyManager)
this.getSystemService(TELEPHONY_SERVICE);
phoneManager.listen(myCallListener,
PhoneStateListener.LISTEN_CALL_STATE);