2

I need to lock the home button in an app, because it will be used by older people and they will not know how to get back if they accidently touch on the home button. I already have that code below but that is not working on android 4.

What I really want is when somebody touches the home button, it does not do anything. Do you have any idea that can help me?

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

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)  {
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ECLAIR
        && (keyCode == KeyEvent.KEYCODE_BACK    || keyCode == KeyEvent.KEYCODE_HOME)
    && event.getRepeatCount() == 0) 
    {
        onBackPressed();
    }
    return super.onKeyDown(keyCode, event);
}

@Override
public void onBackPressed() {
    // Do nothing
    return;
}
Renjith
  • 5,783
  • 9
  • 31
  • 42
  • 1
    Sorry, but I had to. "because it will be used by older people" :) I like it! – Marek Jun 11 '13 at 05:15
  • http://stackoverflow.com/questions/16586789/restrict-the-home-button-android-4-0/16586808#16586808. check this similar question – Raghunandan Jun 11 '13 at 05:16

1 Answers1

3

The only way to do this is to make your app the launcher app on that device, which may not be desirable to the vast majority of Android users, regardless of their age.

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195