如何以编程方式最小化电话呼叫?

时间:2013-09-30 11:44:38

标签: android phone-call

我有一个可以调用“帮助调用”的应用程序。我希望当sombody接受呼叫时,呼叫在后台运行。那么有没有办法最小化电话,同时回到应用程序?

1 个答案:

答案 0 :(得分:1)

您可以尝试这样的事情

private class CallStateListener extends PhoneStateListener {

    @Override
    public void onCallStateChanged(int state, String incomingNumber) {
        switch (state) {
            case TelephonyManager.CALL_STATE_RINGING: {
                break;
            }
            case TelephonyManager.CALL_STATE_OFFHOOK: {
                try {
                    //THIS WILL SIMULATE A HOME BUTTON PRESS
                    //Effectively Minimizing the In Call Screen
                    Intent startMain = new Intent(Intent.ACTION_MAIN);
                    startMain.addCategory(Intent.CATEGORY_HOME);
                    startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    activity.startActivity(startMain);

                    //Now that you are home, and your In Call Screen is minimized
                    //move back to your application
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
            }
        }
    }
}