How to disable the home key

I’d like to lock the screen. I want to disable the home key and only use the back key. How do I accomplish this?

Disable Home Key

i am trying to create a lock screen and for that i need to disable the home button.. i found the following code, its recommended by many and I tried it: @Override public void onAttachedToWindow() { th

How do I disable Home button in Android 4.4.2 [duplicate]

This question already has an answer here: Disable Home button in Android 4.0+ 3 answers In my app i have to disable device’s Home key, my tab supports android 4.4.2 I know how to disable back b

Android – Disable Home key or overide it [closed]

i develop one lock apps, and i want to disable home key while lock open.any one have idea about it. if any one give answer’s it very appreciated.when user press on home button nothing happen , means h

I need to disable Home Key or perform some activity when home key is pressed in android

I need perform some action on press of home key like starting activity when some one presses the home key…how to do it?

Is there a certain way to disable the home key? (related to modding stock apps)

I was just searching for it, and it seems like most people say that it is impossible to disable the home key without making your app an alternate launcher. I’m curious if there is some special way tha

how to disable home button in android?

i want to disable android device home button when my app runs. i have tried following code but it din’t help : @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEve

ICS: How can I disable home button?

I want to disable home button, below code can work before ICS, who have solution to do it on ICS? @Override public void onAttachedToWindow() { this.getWindow().setType(WindowManager.LayoutParams.TYPE_

How can I disable the home, power and search buttons on Android 4.0+?

How can I disable the home, power and search buttons on Android 4.0+?

How can I enable or disable the home button on Android? [closed]

How can I enable or disable the home button on Android tablets?

How to disable Home button android 4.4?

I write lock screen for Android 4.4. I can’t block home button. I start new Activity in onPause function ( or start in service) but If onPause is called by Home button, Activity start delayed 5s. How

Answers

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"/>

Now your application is an alternate Launcher application.

Use the adb, and disable the launcher application using package manager

pm disable com.android.launcher2

Now the Home key press will always stay in the same screen.

Use this method to disable the Home key in android

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

This solution works up to 3.x only.

Okay, this was supposed to be a hard question. But here is a way to crack it.

Override the below method in your Activity,

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

And now handle the key event like this,

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
   if(keyCode == KeyEvent.KEYCODE_HOME)
    {
     Log.i("Home Button","Clicked");
    }
   if(keyCode==KeyEvent.KEYCODE_BACK)
   {
        finish();
   }
 return false;
}

To disable home button, try this:

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

Problem with notification bar pulled down can be solved by hiding notification bar like here:

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.xxxx);
    getWindow().addFlags(LayoutParams.FLAG_FULLSCREEN);
    ....
}

or set fullscreen theme for your Activity or Application in manifest:

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

Please take a look at this answer: http://stackoverflow.com/a/31168147/2968400