Android - Can I turn off the Home button

I have an application, when it starts, I have to disable all the buttons on the Android device, I managed to disable the end call and others. I need to disable the home button press. It should not cause any action when pressed.

Any suggestions highly appreciated

+60
android android widget
Jan 29 '10 at 13:27
source share
6 answers

I’m sure that Toddler Lock just uses BroadcastReciever and listens to Intent.ACTION_MAIN and the Intent.CATEGORY_HOME category - so when you first start it advises you to select the “use this default application” checkbox and forces you to choose a lock for kids.

Thus, it doesn’t really block the Home button at all, it just sets itself as the default broadcast receiver for:

 Intent i = new Intent(Intent.ACTION_MAIN); i.addCategory(Intent.CATEGORY_HOME); 

When you launch Lock Toddler Lock, it probably sets an internal flag, and if you press the home button, it will simply bring the window forward. If the flag is not set, it probably launches Launcher explicitly.

Hope this makes sense. This is just a theory, but I am almost 100% sure that it was so.

+29
Apr 16 '10 at 1:19
source share

Add the following code to your code:

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



Edit:

This works on all older versions of Android. But will not work in ICS and jelly bean and will give you a crash in the application

What does this 4-line Java code mean in an Android app?

+18
Jun 16 '11 at 5:19
source share

Add this to your .xml manifest for your main activity:

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

The HOME button always (re) starts your activity. Works in Froyo.

+10
Jun 21 2018-11-11T00:
source share

I found a way to tackle the HOME key. For your application, set the manifest as

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

The ur app is now an alternative Launcher app.

Use adb and disable launcher application using package manager

 pm disable com.android.launcher2 

Now, pressing the Home button will remain on the same screen.

+5
Dec 27 '10 at 11:50
source share

here you can find my Android application, which is saved on the home page. The button "Home", "Back", "Call", "Power" is disabled. The user can complete the application only by typing the password.

+5
Apr 30 '12 at 8:22
source share

An optional addition to Jeffreys post, here is something that worked for me (and still allows a translucent theme)

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

Try to make the keyboard appear, you can also just disable keyguard while the application is in use:

 KeyguardManager keyguardManager = (KeyguardManager)getSystemService(KEYGUARD_SERVICE); KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE); lock.disableKeyguard(); 

It really works well for creating your own keyboard lock application.

+2
05 Sep 2018-11-11T00:
source share



All Articles