android intercept recent apps button

前端 未结 5 906
暖寄归人
暖寄归人 2020-12-01 07:09

I have an application meant for children and I do not want them to be able to click the \"Recent Apps\" button (the one that looks like two rectangles on top of each other).

5条回答
  •  死守一世寂寞
    2020-12-01 07:27

    The best way I have found is to do this:

    public class BaseActivity extends Activity {
        public void onWindowFocusChanged(boolean hasFocus) {
            super.onWindowFocusChanged(hasFocus);
    
                Log.d("Focus debug", "Focus changed !");
    
            if(!hasFocus) {
                Log.d("Focus debug", "Lost focus !");
    
                Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
                sendBroadcast(closeDialog);
            }
        }
    }// all credit goes here: http://www.juliencavandoli.com/how-to-disable-recent-apps-dialog-on-long-press-home-button/
    

    This is not my own code, but this just hides the recent apps list from showing.

提交回复
热议问题