0

I add this code in my activity

public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_HOME) {
            return false;
        }
        return super.onKeyDown(keyCode, event);
    }

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

and the home button is looks like it is disabled

But the problem is when someone press the menu button and when my menu button is shown and the user press home button then the home button is enabled and home screen is shown

Lukap
  • 31,523
  • 64
  • 157
  • 244
  • You probably already heard it before, but disabling the Home button in Android is really really not recommended – SirDarius Mar 22 '12 at 15:44
  • 3
    The technique you are trying no longer works as of Android 4.0, fortunately, for obvious security reasons. – CommonsWare Mar 22 '12 at 15:48

1 Answers1

0

You should absolutely not be disabling the home button in an Android application. This is a major anti-pattern, and will both make your app labelled as spammy and malware-like. Users hate when you disable their home button, and you should really avoid it at all costs. (At the very least, it will get you poor market ratings.)

Kristopher Micinski
  • 7,572
  • 3
  • 29
  • 34
  • Is it illegal to disable home button and to publish the app to the market ? – Lukap Mar 22 '12 at 16:03
  • Illegal? It's not against the _law_, but your users will get pissed off. You can *try* to do it, but it won't work as of 4.0 (as @CommonsWare points out), and before that users will dislike your app. Don't do it. – Kristopher Micinski Mar 22 '12 at 16:08
  • 2
    There are legitimate reasons to disable the home button. Toddler lock, and some kind of kiosk mode for example. – Seth Archer Brown Apr 06 '12 at 21:04
  • But those are easily defeated by rebooting the phone in safe mode and removing the app, so not really. – Kristopher Micinski Apr 06 '12 at 22:02
  • 6
    custom (non-market) apps may have a good reason to disable buttons (or add custom behaviors to them). a lot of developers use Android for such type of applications (kiosks, sales forces, custom devices, marketing, etc)... – FrancescoR Apr 10 '12 at 08:54
  • But as I said before, these apps are easily uninstallable. The user didn't ask about non market situations, and my response doesn't deal with them. As we've outlined numerous times, the old trick of capturing the home button *no longer works* with the new API, and requires custom firmware changes. So I'm not really sure what your argument for using this method is, as it's both against the design principles for market apps (the OP never mentioned non market) and no longer works. – Kristopher Micinski Apr 10 '12 at 12:02
  • why the downvote? You still can't disable the home button on Android. It's not possible, professional, and quite frankly makes your app spam. – Kristopher Micinski Oct 13 '12 at 17:51
  • @Kristopher there are many practical reason for disabling the HOME Button, it isn't as atrocious as you are making it out to be. Kiosk apps and launcher apps for Toddlers use methodologies for "disabling" (it is really re-directing management) the HOME button. – portfoliobuilder Nov 26 '14 at 19:06
  • @portfoliobuilder Yes, and as I've mentioned extensively here, those methods aren't effective for enabling that purpose. Typically the right way to do these builds is to either build custom firmware or use the right intent receivers: since that's really what they require. I've gotten a lot of down votes for this, but I haven't heard a solution that is anything less than hack. For example, kiosks and child locks can implement the `Intent.CATEGORY_MAIN` receiver, which is a way better way than a hack that doesn't work across implementations. – Kristopher Micinski Nov 30 '14 at 03:52