How to get the call status for outgoing calls?
android, android-activity, android-broadcast, telephonymanager
Solution
Below code help you to get net work status code in onCreate
StateListener phoneStateListener = new StateListener();
TelephonyManager telephonyManager =(TelephonyManager)getSystemService(TELEPHONY_SERVICE);
telephonyManager.listen(phoneStateListener,PhoneStateListener.LISTEN_CALL_STATE);
create an inner class for listening state of phone.
class StateListener extends PhoneStateListener {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
System.out.println("call Activity off hook");
LockScreenActivity.this.finish();
break;
case TelephonyManager.CALL_STATE_IDLE:
break;
}
}
};
Set permission in `manifest` file
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
Problem
I am beginner in android and developing an android application to monitor the network status when the user is on call(for both incoming and outgoing calls)... i can monitor the network status .for incoming calls by implementing the PhonestateListner class and overriding the onCallStateChanged method, i am using the constants (CALL_STATE_IDLE,CALL_STATE_OFFHOOK and CALL_STATE_RINGING) defined in the TelephonyManager class inside the onCallStateChanged method , but these constants are not working properly for outgoing calls... ``` my question is ``` - How to monitor the call status(RINGING,OFF_HOOK, IDLE ) when there is an outgoing call?? - Is there any API in android to monitor the call status for outgoing calls??? if yes, then please specify... please help me to understand this concept... Thanks for your time