当用户切断拨出电话时,如何返回相同的片段

时间:2016-11-18 10:09:34

标签: android android-fragments broadcastreceiver phone-state-listener

当用户切断按钮的onClick()方法发出的拨出电话时,如何返回相同的片段  我有一个片段中的按钮,我打开对话框,然后在对话框的按钮点击电话呼叫活动开始 在这里我放了一些代码,我的呼叫状态听众请帮助我

//拨打电话

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

//我的电话呼叫状态监听器

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;
                }
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

我使用下面的代码,它可以正常工作。它在通话结束后返回。

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);

尝试使用它,如果它适合你。