How to handle home button click event in custom lock screen application

540 views Asked by At

I am working in a project where custom lock screen must be implemented once the user clicks the lock button. After clicking, the application should be locked and should also prevent from closing the app while pressing home button. I used following code to disable home key pressed state:

@Override
    public void onAttachedToWindow(){ 
        Log.i("TESTE", "onAttachedToWindow");
        this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
        super.onAttachedToWindow(); 
    }
    public boolean onKeyDown(int keyCode, KeyEvent event){
    if (keyCode == KeyEvent.KEYCODE_HOME) {
        Log.i("TESTE", "BOTAO HOME");
        return true;
    }

The problem with above method is not working for latest versions. So it would be very much helpful if you mentor me by any alternative solutions to achieve this task. Thanks in advance

1

There are 1 answers

1
Don Chakkappan On

You can not override the home key button.