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



>我有一个可以调用"帮助呼叫"的应用程序。我希望当 sombody 接受呼叫时,呼叫在后台运行。那么有没有办法最大限度地减少电话呼叫,同时回到应用程序?

你可以试试这样的东西

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

最新更新