This solution only works with 3.x.
Well, that should have been a difficult question. But here is a way to crack it.
Cancel the method below in your activity,
@Override public void onAttachedToWindow() { super.onAttachedToWindow(); this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD); }
And now handle a 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; }
Andro Selva Jan 17 '12 at 5:05 2012-01-17 05:05
source share