Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Is It possible to disable the click of home button

I have an application, when it launches I have to disable all the buttons on Android device, I succeeded in disabling end call and others. I need to disable home button click. It should not produce any action on click.

Any suggestions highly appreciated

like image 850
Vinayak Bevinakatti Avatar asked Jan 29 '10 13:01

Vinayak Bevinakatti


People also ask

Can I disable Home button on Android?

Navigate to Android > Restrictions > Basic and click on Configure. Under Allow Device Functionality, you'll have the options to disable Home/Power button. Home Button-Uncheck this option to restrict users from using the Home Button. Power Off-Uncheck this option to restrict users from turning their devices off.

How do I bypass the home button on Android?

This example demonstrates how do I in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.


2 Answers

Add following code to your activity:

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

Edit:

This works in all older version of android. But will not work in ICS and jelly bean and will give you crash in app

What does this 4 line java code means in android application?

like image 36
Jeffrey Avatar answered Oct 07 '22 14:10

Jeffrey


I'm pretty sure Toddler Lock just uses a BroadcastReciever and listens for Intent.ACTION_MAIN and the category Intent.CATEGORY_HOME - that's why when you first launch it, it tells you to check the "use this application as default" box, and makes you select toddler lock.

So, it's not really blocking the Home button at all, it's just setting itself up as the default broadcast receiver for:

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

When you launch Toddler Lock, it probably sets an internal flag, and if you press the home button, it just brings the window to the front. If the flag is not set, it probably launches Launcher explicitly.

I hope that makes sense. It's just a theory, but I'm almost 100% sure that's how it's done.

like image 149
synic Avatar answered Oct 07 '22 16:10

synic