我想在android应用程序中检测传出呼叫。实际上,我可以检测出呼出的电话,但它也对呼入工作,我不想那样。我需要它只为外向工作。这是我的代码…

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;
}

最佳答案

您可以为android.intent.action.NEW_OUTGOING_CALL编写广播接收器。
See here示例代码可用

关于android - PhoneStateListener中的传出调用检测,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4377933/

10-13 03:47