3

如何使用 PhoneStateListener 识别被拒绝的呼叫和未接的呼叫?在我的代码中,我只发送短信拒绝来电而不是未接来电。请验证以下代码。

class PhoneStateChangeListener extends PhoneStateListener{
public static boolean wasRinging;

SmsManager smsManager = SmsManager.getDefault();
 @Override
public void onCallStateChanged(int state, String incomingNumber) {

    switch(state){
        case TelephonyManager.CALL_STATE_RINGING:
             Log.e("pppp", "RINGING");
             // Ringing 
            wasRinging=false;
             break;
        case TelephonyManager.CALL_STATE_OFFHOOK:
            Log.e("Lifttttttt", "OFFHOOK");
            //Received calls

             wasRinging = true;
             break;
        case TelephonyManager.CALL_STATE_IDLE:
           Log.e("Endddddddd", "IDLE");
            if(!wasRinging ){

            //Missed or Rejected calls

            }
             wasRinging = true;
             break;
    }

    super.onCallStateChanged(state, incomingNumber);
   }
}

编辑:有没有可能?请给重播。谢谢。

4

0 回答 0