How to disable home button in Android like lock screen apps do?

后端 未结 6 1752
后悔当初
后悔当初 2020-12-24 14:43

I know this question is asked many times but I found that none of the solution is working. I tried the code given below...

   protected void onPause() {
            


        
6条回答
  •  情深已故
    2020-12-24 15:12

    What you could do is override the home key function like this:

    @Override public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        if(keyCode == KeyEvent.KEYCODE_HOME)
        {
            //The Code Want to Perform.
        }
    });
    

    Then you should be able to prevent the user to go back to home screen using this button. Hope that works for you.

    EDIT: The problem with overriding the home button is it is considered as a security hole by Google, so each time someone finds a way to override it Google patches this "hole".  

提交回复
热议问题