title: Disable Home Button in Homescreen app?
body: <p>I am working on a research project for my university. The app will never be put on the market and only used for research.</p>
  
  <p>I have made a homescreen app by using the Google Homescreen sample code.
  In there, I have made an activity that is a lockscreen.
  While in there, the user should not be able to get out of the lock by pressing Home, Back, etc.
  The Back-Button seems to be disabled, but the Home-Button is not.
  I have tried several solutions from the internet and stackoverflow, which are all not working.</p>
  
  <p>Here is the important code:</p>
  
  <p>(<strong>Notice</strong>: Logcat shows "Button pressed: 4" for the Back-Button but nothing for the home button!)</p>
  
  <p>In my Lock-Screen Activity:</p>
  
  <pre><code> @Override
      public boolean onKeyDown(int keyCode, KeyEvent event) {
          Log.v(TAG, "BUTTON PRESSED: " + new Integer(keyCode).toString());
  
          if ((keyCode == KeyEvent.KEYCODE_BACK)) {
              return true;
          } else if ((keyCode == KeyEvent.KEYCODE_CALL)) {
              return true;
          }
          else if ((keyCode == KeyEvent.KEYCODE_HOME)){
              return true;
          }
          return super.onKeyDown(keyCode, event);
      }
  
      @Override
      public void onAttachedToWindow() {
          this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
          super.onAttachedToWindow();
      }
  </code></pre>
  
  <p>It seems like the onAttachedToWindow() Method is not working since Android Version 4.
  How can I disable the homebutton?</p>
  
  <p><strong>EDIT: Manifest file:</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.android.home" &gt;
  
      &lt;uses-permission android:name="android.permission.CALL_PHONE" /&gt;
      &lt;uses-permission android:name="android.permission.GET_TASKS" /&gt;
      &lt;uses-permission android:name="android.permission.READ_CONTACTS" /&gt;
      &lt;uses-permission android:name="android.permission.SET_WALLPAPER" /&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="android.permission.EXPAND_STATUS_BAR" /&gt;
      &lt;uses-permission android:name="android.permission.NFC" /&gt;
      &lt;uses-permission android:name="android.permission.DISABLE_KEYGUARD" /&gt;
  
      &lt;permission android:name="android.permission.WRITE_SECURE_SETTINGS" &gt;
      &lt;/permission&gt;
  
      &lt;application
          android:icon="@drawable/ic_launcher_home"
          android:label="@string/home_title" &gt;
          &lt;service android:name=".MyService" &gt;
          &lt;/service&gt;
  
          &lt;activity
              android:name="Home"
              android:launchMode="singleInstance"
              android:stateNotNeeded="true"
              android:theme="@style/Theme" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.HOME" /&gt;
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
  
  
              &lt;/intent-filter&gt;
  
              &lt;receiver android:name=".ScreenReceiver" &gt;
                  &lt;intent-filter&gt;
                      &lt;action android:name="android.intent.action.SCREEN_ON" /&gt;
                      &lt;action android:name="android.intent.action.SCREEN_OFF" /&gt;
                      &lt;action android:name="android.intent.action.USER_PRESENT" /&gt;
                  &lt;/intent-filter&gt;
              &lt;/receiver&gt;
          &lt;/activity&gt;
          &lt;activity
              android:name="Wallpaper"
              android:icon="@drawable/bg_android_icon"
              android:label="Wallpaper" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.SET_WALLPAPER" /&gt;
  
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity android:name=".LockPage" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.SCREEN_ON" /&gt;
                  &lt;action android:name="android.intent.action.SCREEN_OFF" /&gt;
                  &lt;action android:name="android.intent.action.USER_PRESENT" /&gt;
                  &lt;action android:name="android.nfc.action.NDEF_DISCOVERED" /&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.HOME" /&gt;
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
                  &lt;category android:name="android.intent.category.MONKEY" /&gt;
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
  
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;data android:mimeType="text/plain" /&gt;
              &lt;/intent-filter&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.nfc.action.NDEF_DISCOVERED" /&gt;
  
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
  
                  &lt;data android:scheme="http" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>