My question is self explanatory.
I have searched a lot but could not found the way to handle Recent activity button click.
I want to ignore the hardware button clicks of Recent Activity button from the status bar from android 3.0 tablet.
Currently what I have tried so far is:
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK)
{
return true;
}
// in the same way I have written it for KEYCODE_HOME
}
can you tell me what should I write to handle recent activity button?
Thanking you in advance. 🙂
EDIT: This is what I have tried now. The KEYCODE_APP_SWITCH is not working.
public boolean onKeyDown(int keyCode, KeyEvent event) {
Log.e("INSIDE", "LOCKDEMO");
if (keyCode == KeyEvent.KEYCODE_BACK) {
Log.e("KEY EVENT", "BACK");
return true;
}
if (keyCode == KeyEvent.KEYCODE_HOME) {
Log.e("KEY EVENT", "HOME");
return true;
}
if(keyCode == KeyEvent.FLAG_FROM_SYSTEM) {
Log.e("KEY EVENT", "SYSTEM");
return true;
}
if(keyCode == KeyEvent.FLAG_KEEP_TOUCH_MODE) {
Log.e("KEY EVENT", "TOUCH MODE");
return true;
}
if(keyCode == KeyEvent.FLAG_SOFT_KEYBOARD) {
Log.e("KEY EVENT", "SoFT KEYBOARD");
return true;
}
if(keyCode == KeyEvent.FLAG_VIRTUAL_HARD_KEY) {
Log.e("KEY EVENT", "HARDWARE KEY");
return true;
}
if(keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Log.e("KEY EVENT", "APP SWITCH");
return true;
}
Log.e("KEY EVENT", "NOT HANDLED");
return super.onKeyDown(keyCode, event);
}
When I press on RecentAppBtn, it does not even print the last Log statement i.e. Event not handled.
From peeking into the docs, I think that
KeyEvent.KEYCODE_APP_SWITCHis what you’re searching for.You could however also use the
KeyEvent.getKeyCode()-method (on theevent-parameter) to see which key-code is triggered (and if there is any key triggered), when you press the application switcher.I played around with this for a while and I have come to the conclusion, that it’s not possible.
The
KEYCODE_APP_SWITCH-event is not delivered to eitheronKeyDown()nordispatchKeyEvent(). Ergo, It can not be handled.Also, you’ll run into problems on Android 4 devices, because the
KEYCODE_HOME-event is also no longer dispatched to any of the above methods. See the docs:It also seems that there is no real easy approach to creating a real lock-screen yourself. See this discussion: Developing a custom lock screen
It is well possible to show some custom information on the default lock-screen: Is there a way for me to show a customized message on the lock screen?
For the sake of completeness: In Android L, you’ll be able to “lock users in your app”, so you don’t need to manually override the Hardware keys. Here’s the relevant information: