ravi_koriya ravi_koriya - 1 year ago 51
Android Question

how can i return back to same fragment when user cuts outgoing call

How can i return back to same fragment when user cuts outgoing call made by onClick() method of button
i have a button in fragment from where i open dialog and on dialog's button click phone call activity is starting
here i put some code and my call state listener kindly help me

// phone call made

String temp = "tel:+91"+"xxxxxxxxxx";
Intent callIntent = new Intent(Intent.ACTION_CALL);

// my phone call state listener

private class PhoneCallStateListener extends PhoneStateListener
private boolean isSystemCalling = false;
public void onCallStateChanged(int state, String incomingNumber) {
if (TelephonyManager.CALL_STATE_OFFHOOK == state)
isSystemCalling = true;
if (TelephonyManager.CALL_STATE_IDLE == state)
if (isSystemCalling)
isSystemCalling = false;

Answer Source

I used below codes and it's working as you want. It's returning after call.

Uri number = Uri.parse("tel:" + contactNumber);
Intent dial = new Intent(Intent.ACTION_CALL, number);
if (ActivityCompat.checkSelfPermission(mContext, android.Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                                // TODO: Consider calling
                                //    ActivityCompat#requestPermissions
                                // here to request the missing permissions, and then overriding
                                //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
                                //                                          int[] grantResults)
                                // to handle the case where the user grants the permission. See the documentation
                                // for ActivityCompat#requestPermissions for more details.

Try using that if it works for you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download