android - Catch back button press event when screen locked -


i trying write small app catch keyevent of button been pressed, when screen locked.
saw can override onkeydown or onbackpressed in order catch event, work if activity running.
understand on of android phones, if not on of them, os doesn't listen , menu buttons while screen locked.

edit
have read couple of posts capturing event of user pressing volume buttons, , says isn't way when screen off.
reason belive case change regarding button?

1)register broadcast receiver intent.action_screen_off , intent.action_screen_on

2) check if screen locked using keyguard manager :

keyguardmanager kmanager = (keyguardmanager) getsystemservice(context.keyguard_service); boolean islocked = kmanager.inkeyguardrestrictedinputmode(); 

or without using broadcast receiver, can check :

keyguardmanager kmanager = (keyguardmanager) context.getsystemservice(context.keyguard_service); if( kmanager .inkeyguardrestrictedinputmode()) {  //locked } else {  //not locked  } 

next check button press event if screen locked.

@override public boolean onkeydown(int keycode, keyevent event) { if ((keycode == keyevent.keycode_back)) {    //back button pressed } return super.onkeydown(keycode, event); } 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -