How to disable android home button

Asked

Viewed 20,153 times

1

I need to disable the use of the physical button of the Android device (preferably versions higher than 4.0). With researches I found some solutions such as removing actionbar, leaving the application in "fullscreen". I need to use actionbar. I found a not very good solution, which uses the following tags in the manifest:

<category android:name="android.intent.category.HOME" />                 
<category android:name="android.intent.category.DEFAULT" />               
<category android:name="android.intent.category.MONKEY"/>

With this presents a popup asking what action I want to use, Home Screen of the device or call my application. When selecting my application, a new application instance is created...

In short, I need to block the activation/ use of the device’s home physical button within the application. I can’t remove actionbar, I can’t start a new application instance, and I can’t block the back button (physical back button).

  • That question of the SO discusses this theme. Specifically, the first response to the question seems to work. I have not yet tested, but...

  • But I cannot remove actionbar, the first removes the action.

  • Hi Victor! Got it... In that case, it would be interesting for you to edit the question to make that clear, so the staff doesn’t have to come read the comments.

  • I made the Carlos edition, thanks for your help!

2 answers

1

The Android Home button for security reasons was made so it could not be blocked by apps.

Any way you find to do this is basically a Hack that there is no guarantee that will work or that will behave the same way in all versions of Android or even on different devices or that use a custom UI, only with the Android SDK will not have anything that allows you to do this.

The only way to do this without using any gimmick is if your App is a Home Screen, the Home Screen will be the only app that will be able to handle the Home key.

0

Try to import this solution https://github.com/shaobin0604/Android-HomeKey-Locker

Lets lock both the boot PHYSICIST HOME, BACK or MENU key in verses 4.0+

in your code just use:

HomeKeyLocker homeKeyLoader = new HomeKeyLocker();
homeKeyLocker.lock(this);
     // home key locked 
homeKeyLocker.unlock();
     // home key unlocked 
  • Pedro, I used the project you informed me. Unfortunately this very strange the functioning of it in my system. I don’t know if it’s because I use actionbar and Fragments. By pressing the home button, it displays the device’s home screen but without the icons. Only the device returns to normal (presenting the icons) finishing the application. And, the project prevents the use of the physical back button. I need it functional. Thanks for the help although unfortunately it does not work.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.