0

1.我想从应用程序片段页面拨打电话按钮点击它的作品很好。

2.从片段页面拨打电话后,重新启动APP。

3.我想停止这个。只需要打开相同的片段页面,无需重新启动应用程序

我的代码:

private class MyPhoneListener extends PhoneStateListener
{

    private boolean onCall = false;

    @Override
    public void onCallStateChanged(int state, String incomingNumber)
    {

        switch (state)
        {
            case TelephonyManager.CALL_STATE_RINGING:
                // phone ringing...
                //Toast.makeText(FindStores_tabviewonclick_showpage.this, incomingNumber + " calls you", Toast.LENGTH_SHORT).show();
                break;

            case TelephonyManager.CALL_STATE_OFFHOOK:
                // one call exists that is dialing, active, or on hold
                //Toast.makeText(FindStores_tabviewonclick_showpage.this, "on call...", Toast.LENGTH_SHORT).show();
                //because user answers the incoming call
                onCall = true;
                break;

            case TelephonyManager.CALL_STATE_IDLE:
                // in initialization of the class and at the end of phone call

                // detect flag from CALL_STATE_OFFHOOK
                if (onCall == true)
                {
                    //Toast.makeText(Find_stores.this, "restart app after call", Toast.LENGTH_LONG).show();

                    Log.i("AFTER PHONE Call", "restart app");
                    // restart our application
                    Intent restart = getActivity().getPackageManager().getLaunchIntentForPackage(getActivity().getPackageName());
                    restart.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    //.restart.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    startActivity(restart);



                    onCall = false;
                }
                break;
            default:
                break;
        }

    }
}
4

2 回答 2

1

在 TelephonyManager.CALL_STATE_IDLE 中更改意图标志:

 Intent restart = getActivity().getPackageManager().getLaunchIntentForPackage(getActivity().getPackageName());
               restart.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);

                startActivity(restart);
于 2016-07-09T11:56:07.210 回答
0

用这个

getActivity().getFragmentManager().beginTransaction().remove(YourCurrentFragment.this);
于 2016-07-09T10:14:59.600 回答