Q: Accessibility Service - Disable home button action android I want to disable home button action using the accessibility service. I already read the docs from https://developer.android.com/training/accessibility/service
but didn't understand how to do it? Can anyone help me out in this

A: Create your own Accessibility Service using any tutorial and put this code inside it....
public class button_lock extends AccessibilityService {
@Override
public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) {

}

@Override
public void onInterrupt() {

}
@Override
protected boolean onKeyEvent(KeyEvent event) {
    if(event.getKeyCode()==KeyEvent.KEYCODE_HOME)
        return true;
    else
       return super.onKeyEvent(event);
}}

Then enjoy....

A: 
Override the below method in your Activity,

@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();
    this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);           
}


And now handle the key event like this,

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
   if(keyCode == KeyEvent.KEYCODE_HOME)
    {
     Log.i("Home Button","Clicked");
    }
   if(keyCode==KeyEvent.KEYCODE_BACK)
   {
        finish();
   }
 return false;
}


A: You can Disable Home Key by adding this code in your activity:
@Override
public void onAttachedToWindow() {
    this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
    super.onAttachedToWindow();
}

However, this doesn't work while dialog is showing. To get rid of this problem simply add my code to your Dialog object:
Disable home Key while Dialog showing
