Ringing State Out Going Calls
I have the following code and I have read that for outgoing calls ringing state is active when phone call between two parties is connected and other party can actually see that you
Solution 1:
TelephonyManager.CALL_STATE_RINGING
is meant for the incoming call. Its not for the ringing of other side for an outgoing call.
TelephonyManager.CALL_STATE_RINGING
will be triggered when you have an incoming call and your phone is ringing.
and also for your information. There is no public api to detect the ringing state of other side for outgoing call.
Solution 2:
Maybe try out this helper class i copied somewhere online, cannot remember where
/*Helper class to detect incoming and outgoing calls.*/publicclassCallHelper {
private Activity activity;
private TelephonyManager tm;
private CallStateListener callStateListener;
private OutgoingReceiver outgoingReceiver;
public String TelephoneNumber;
publicbooleanInCall=false;
publicCallHelper(Activity activity) {
this.activity = activity;
callStateListener = newCallStateListener();
outgoingReceiver = newOutgoingReceiver();
}
/*Listener to detect incoming calls.*/privateclassCallStateListenerextendsPhoneStateListener {
@OverridepublicvoidonCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING: {
TelephoneNumber = incomingNumber;
inout = "in";
InCall = false;
break;
}
case TelephonyManager.CALL_STATE_OFFHOOK: {
if (!InCall) {
InCall = true;
//Do your stuff here when in call...
}
break;
}
case TelephonyManager.CALL_STATE_IDLE: {
InCall = false;
break;
}
default: {
InCall = false;
break;
}
}
}
}
/*Broadcast receiver to detect the outgoing calls.*/publicclassOutgoingReceiverextendsBroadcastReceiver {
publicOutgoingReceiver() { }
@OverridepublicvoidonReceive(Context context, Intent intent) {
TelephoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
}
}
/*Start calls detection.*/publicvoidstart() {
tm = (TelephonyManager) activity.getSystemService(Activity.TELEPHONY_SERVICE);
tm.listen(callStateListener, PhoneStateListener.LISTEN_CALL_STATE);
IntentFilterintentFilter=newIntentFilter(Intent.ACTION_NEW_OUTGOING_CALL);
activity.registerReceiver(outgoingReceiver, intentFilter);
}
/*Stop calls detection.*/publicvoidstop() {
tm.listen(callStateListener, PhoneStateListener.LISTEN_NONE);
activity.unregisterReceiver(outgoingReceiver);
}
}
Post a Comment for "Ringing State Out Going Calls"