ravi_koriya ravi_koriya - 21 days ago 5
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);
callIntent.setData(Uri.parse(temp));
startActivity(callIntent);


// 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)
{
if(!active)
{
db.update_activity(Utilities.CONST_SYS_STATUS,Utilities.STATUS_DEACTIVE);
update();
}
else
{
db.update_activity(Utilities.CONST_SYS_STATUS,Utilities.STATUS_ACTIVE);
update();
}
isSystemCalling = false;
}
}
}
}

Answer

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.
     return;
}
mContext.startActivity(dial);

Try using that if it works for you.