2

I have trying to get ringing stage of the outgoing call. I have already try BroadcastReceiver with NEW_OUTGOING_CALL and PHONE_STATE action. But I am not getting the Ringing Stage of the reciever. I understand now that receiver does not tell you ringing stage. I have seen this same query:- Android - How to detect outgoing call is answered or received? I have also apply this solution but still I am not getting any solution. I have declare the Service with action NotificationListenerService I need to do extra or something else...

I think to get the ringing stage of the outgoing call or to get pick up the call on other end this is possible..

Please help!

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Sayam
  • 35
  • 6
  • I have seen responses indicating there is no way to determine whether the line on the other end of an outgoing call is ringing. I don't know this for a fact though. – nasch Jul 07 '17 at 17:06

1 Answers1

-1

In the manifest file you should have the following permissions to check the outgoing call:

<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>

and the code of broadcast receiver:

public class PhoneStateChecking extends BroadcastReceiver {
    boolean hasCallStateRinging = false;

    @Override
    public void onReceive(Context context, Intent intent) {

        Log.d("Intent", intent.toString());
        if(intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
            Log.e("CAll-STATUS", "out going Call");
        }

        //        Checking for the call status
        try {
            // TELEPHONY MANAGER class object to register one listner
            TelephonyManager tmgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            //Create Listner
            MyPhoneStateListener PhoneListener = new MyPhoneStateListener();
            // Register listener for LISTEN_CALL_STATE
            tmgr.listen(PhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class MyPhoneStateListener extends PhoneStateListener {
        public void onCallStateChanged(int state, String incomingNumber) {
            switch (state) {
                case TelephonyManager.CALL_STATE_RINGING:
                    if (hasCallStateRinging)
                        return;
                    else {
                        hasCallStateRinging = true;
                        Log.e("CAll-STATUS", "CALL_STATE_RINGING");
                    }
                    break;
                case TelephonyManager.CALL_STATE_OFFHOOK:
                    if(!hasCallStateRinging){
                        hasCallStateRinging = true;
                        Log.e("CAll-STATUS", "CALL_STATE_OFFHOOK");
                    }
                    break;
                case TelephonyManager.CALL_STATE_IDLE:
                    if (hasCallStateRinging) {
                        hasCallStateRinging = false;
                        Log.e("CAll-STATUS", "CALL_STATE_IDLE");
                    }
                    break;
            }
        }
    }

}
danday74
  • 52,471
  • 49
  • 232
  • 283
karthik
  • 347
  • 1
  • 9