title: Disable device's home button programmatically in android
body: <p>I am new to android and developing android application with lock functionality.i want to disable device's home button in an activity and i am googled for it from last 4 days and i am not getting correct solution for it.i am tried all the solution that i get in below link,but i am not able to disable home button.please suggest me how to disable home and all device's key programmatically.any help would be appreciated.<br>
  here is the link that i visited and tried the solutions that described their.<br>
  <a href="https://stackoverflow.com/questions/26296963/how-to-disable-android-hardware-buttons-programmatically">How to disable android hardware buttons programmatically?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/3953689/how-to-lock-android-buttons-phone-from-code-screen-lock">How to lock android buttons/phone from code (screen lock)?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/3898876/how-to-disable-the-home-key">How to disable the home key</a></p>
  
  <p><a href="http://sunil-android.blogspot.in/2013/07/mostly-used-android-code.html" rel="nofollow noreferrer">http://sunil-android.blogspot.in/2013/07/mostly-used-android-code.html</a></p>
  
  <p><a href="http://www.technonutty.com/2013/11/disable-home-power-back-button-android.html" rel="nofollow noreferrer">http://www.technonutty.com/2013/11/disable-home-power-back-button-android.html</a></p>
  
  <p>Here is the code that i lastly edited:<br>
  <strong>MainActivity.java</strong>  </p>
  
  <pre><code>package com.example.lockdemo;   
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  
  public class MainActivity extends Activity {
  
      private LockLayer lockLayer;
      private View lockView;
      Button button1;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          init();
  
          button1 = (Button)lockView.findViewById(R.id.button1);
          button1.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  lockLayer.unlock();
                  finish();
              }
          });
      }
  
      private void init() {
          lockView = View.inflate(this, R.layout.activity_main, null);
  
          lockLayer = LockLayer.getInstance(this);
          lockLayer.setLockView(lockView);
          lockLayer.lock();
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
          if (id == R.id.action_settings) {
              return true;
          }
          return super.onOptionsItemSelected(item);
      }
  }
  </code></pre>
  
  <p><strong>LockLayer.java</strong></p>
  
  <pre><code>public class LockLayer {
      private Activity mActivty;
      private  WindowManager mWindowManager;
      private View mLockView;
      private LayoutParams mLockViewLayoutParams;
      private static LockLayer mLockLayer;
      private boolean isLocked;
  
      public static LockLayer getInstance(Activity act){
          if(mLockLayer == null){
              mLockLayer = new LockLayer(act);
          }
          return mLockLayer;
      }
  
      private LockLayer(Activity act) {
          mActivty = act;
          init();
      }
  
      private void init(){
          isLocked = false;
          mWindowManager = mActivty.getWindowManager();
          mLockViewLayoutParams = new LayoutParams();
          mLockViewLayoutParams.width = LayoutParams.MATCH_PARENT;
          mLockViewLayoutParams.height = LayoutParams.MATCH_PARENT;
          mLockViewLayoutParams.type = LayoutParams.TYPE_SYSTEM_ERROR;
      }
      public void lock() {
          if(mLockView!=null){
              mWindowManager.addView(mLockView, mLockViewLayoutParams);
          }
          isLocked = true;
      }
      public void unlock() {
          if(mWindowManager!=null &amp;&amp; isLocked){
              mWindowManager.removeView(mLockView);
          }
          isLocked = false;
      }
      public void setLockView(View v){
          mLockView = v;
      }
  }
  </code></pre>
  
  <p><strong>activity_main.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.lockdemo"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="8"
          android:targetSdkVersion="21" /&gt;
  
      &lt;uses-permission android:name="android.permission.DISABLE_KEYGUARD" /&gt;
      &lt;uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name=".MainActivity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>Thank you.</p>