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