Thursday, 20 March 2014

Disable home button in Android

Due to the security reason ICS is not allowing to disable home button in android after 4.X ; it is possible  before 4.x version of android;

Code Snippet  :
@Override
        public void onAttachedToWindow() {
              LoadFirstPageObject();
           this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
            super.onAttachedToWindow();

        }

And you can throw the own handle type by
@Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            if ((keyCode == KeyEvent.KEYCODE_HOME)) {
             
               // Toast.makeText(this, "You pressed the home button!", Toast.LENGTH_LONG).show();                     
                return true;
            }
           
            return super.onKeyDown(keyCode, event);
        }


Below code will create problem exception in 4.x as illegal illegalargumentexception;
It won't work on Nexus

  this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);


No comments:

Post a Comment