0

i am trying to create a lock screen and for that i need to disable the home button..

i found the following code, its recommended by many and I tried it:

@Override
public void onAttachedToWindow()
{  
    this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);     
    super.onAttachedToWindow();  
}

@Override

public boolean onKeyDown(int keyCode, KeyEvent event) {
    return false;
}

Now i know what its doing, I tried it on HTC Explorer, Sony Ericsson Experia Neo V, and Samsung Galaxy S2..

The code works in HTC and Sony but it seems to have no effect on Samsung Galaxy s2.. Please note that Samsung is rooted while others not...is rooted device the problem??

Any Suggestions pls?

user632905
  • 990
  • 9
  • 19
  • 2
    you can no longer catch the home key on newer (4.0) versions of Android like this, for a number of reasons, don't do it. – Kristopher Micinski Mar 24 '12 at 20:31
  • well i do have a workaround of locking the home button but its kinda messy so i was thinking about using this small piece..i guess i have to do the messy work then...but I Can catch the home intent in 4.0 right? – user632905 Mar 24 '12 at 20:36
  • I have seen that some media players have their own lock screens. Try to test them on your htc/sony devices. It is interesting how do they work on 4.0 devices – pleerock Mar 24 '12 at 20:42

2 Answers2

3

I believe the problem is that the Home key really isn't meant to be disabled.

dldnh
  • 8,923
  • 3
  • 40
  • 52
1

The only way to overwrite the home button in android is to act as a home replacement, so your app is opened when home is pressed. The user has to set your app as default app and when the screen is unlocked you open the default launcher.

The lockscreen in android isn't meant to be replaced.

Gabriel Ittner
  • 1,162
  • 9
  • 22