我要检测android应用呼出。其实我可以检测呼出电话,但它也工作过传入,我不希望出现这种情况。我需要它传出才起作用。这里是我的code ....
布尔振铃= FALSE;布尔摘机= FALSE;公共无效onCallStateChanged(INT状态,弦乐incomingNumber){ 开关(州){ 案例TelephonyManager.CALL_STATE_IDLE: 如果((铃声)及!&安培;摘机){ ///进来的电话 } 打破;案例TelephonyManager.CALL_STATE_RINGING: callerPhoneNumber = incomingNumber; Log.d(TAG,振铃); 振铃= TRUE; 摘机= FALSE; 打破; 案例TelephonyManager.CALL_STATE_OFFHOOK: Log.d(TAG,摘机); 摘机= TRUE; 振铃= FALSE; 打破;}
解决方案
您可以写一个广播接收器 android.intent.action.NEW_OUTGOING_CALL
。
看到这里样品code是可用
I want to detect outgoing call in android application . Actually I can detect outgoing calls but it is also working for incoming too and I don't want that. I need it to work only for outgoing. here is my code....
boolean ringing = false;
boolean offhook = false;
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
if((!ringing)&& offhook){
///incomming call
}
break;
case TelephonyManager.CALL_STATE_RINGING:
callerPhoneNumber = incomingNumber;
Log.d(TAG, "RINGING");
ringing = true;
offhook = false;
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.d(TAG, "OFFHOOK");
offhook = true;
ringing = false;
break;
}
解决方案
You can write a broadcast receiver for android.intent.action.NEW_OUTGOING_CALL
.
See here Sample code is available