现在我可以调用按键并处理呼叫事件,但它不起作用。
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);
答案 0 :(得分:1)
可以通过编程方式拨打电话,并根据需要添加DTMF铃声和暂停:
Intent i = new Intent("android.intent.action.CALL",Uri.parse("tel://" + number + ',' + dtmf));
虽然它是requested feature,但无法在呼叫过程中决定将DTMF音调插入音频上行链路。
答案 1 :(得分:0)
您的代码将为您的活动生成关键事件,而非电话应用程序。
据我所知,实现你想要的东西是不可能的,但我可能是错的。但是,如果可能的话,这是一个潜在的问题,因为任何应用程序都可以在电话呼叫期间发送任何触摸屏,并在用户不知情的情况下触发坏事。