I know this question has been asked many times but none of the solution provided seems to work for me. I have tried here,here and here
My requirement :- I want to over-ride the HOME BUTTON and the RECENT APPS button on android. I know this not a best but the requirement is as such that I have to do it.
My Code :-
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_HOME)
{
Log.d("Key","Home button clicked");
return false;
}
if(keyCode == KeyEvent.KEYCODE_MOVE_HOME)
{
Log.d("Key","Home button clicked Msg 2");
return false;
}
return super.onKeyDown(keyCode, event);
}
But the onKeyDown() never gets called. And I get IllegalArgumentException: Window type can not be changed after the window is added error.
I know one way to disable the HOME button is to make my app behave like an launcher app. But is there any better way to do it ?