Skip to content Skip to sidebar Skip to footer

Activity Popups Over Incoming Call Screen

I'm trying to override the incoming call screen - I know I can't change it so I'm trying to popup an activity ontop. My code works fine except when the phone has been idle for a fe

Solution 1:

When the phone screen is off and there is an incoming call, there are more work to do (waking up, dealing with the keyguard view...) so the in-call activity take longer to show up and this lead to the case your Call activity starts earlier than the in-call activity starts --> the in-call activity is on top There is no exact time that the in-call activity need to displays (you have tried and see that 700 miliseconds is not enough) My solution: keep tracking the state of Call activity:

  • If it's still on top and user has not dismiss it (or any condition to dismiss), just keep tracking using the handler
  • If there is any other activity go to foreground then Call activity try to get the back to top

My sample activity:

publicclassMainActivityextendsActivity {
    private ActivityManager mActivityManager;
    privatebooleanmDismissed=false;

    privatestaticfinalintMSG_ID_CHECK_TOP_ACTIVITY=1;
    privatestaticfinallongDELAY_INTERVAL=100;

    @OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Windowwindow= getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);

        mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        mHandler.sendEmptyMessageDelayed(MSG_ID_CHECK_TOP_ACTIVITY,
                DELAY_INTERVAL);
    }

    privateHandlermHandler=newHandler() {
        publicvoidhandleMessage(android.os.Message msg) {
            if (msg.what == MSG_ID_CHECK_TOP_ACTIVITY && !mDismissed) {
                List<RunningTaskInfo> tasks = mActivityManager
                        .getRunningTasks(1);
                StringtopActivityName= tasks.get(0).topActivity
                        .getClassName();
                if (!topActivityName.equals(MainActivity.this
                        .getComponentName().getClassName())) {
                    // Try to show on top until user dismiss this activityIntenti=newIntent();
                    i.setClass(MainActivity.this, MainActivity.class);
                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    i.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
                    startActivity(i);
                }
                sendEmptyMessageDelayed(MSG_ID_CHECK_TOP_ACTIVITY,
                        DELAY_INTERVAL);
            }
        };
    };

}

Post a Comment for "Activity Popups Over Incoming Call Screen"