Search code examples
androidwindow-managers

Android: Using Windowmanager to make the HOME button unwork


I have already finished an Android lock-screen app but my teacher asks me to change it into an app using Windowmanager so that users can not exit the app using HOME button. The idea is that we can make the whole app be a float full-screen window. But I don't know how to change a finished activity into a float window.


Solution

  • You just can't override the HOME button (or "make the HOME button unwork").

    There was a time, about in Android 1.6 when you could do that, against Google's wishes. But now you just can't.

    Think about it. If you could do that, some app you downloaded from the PlayStore could do that and render your phone unusable.

    The closest you can get is adding CATEGORY_HOME as an intent of one of your activities. That way when the user touches the HOME button, he will be presented with the option to choose which activity will open when they touch HOME.

    Here you've got an example on how to do it (you don't have to change anything in the Activity classs):

     <activity           
        android:name="com.mpascual.example.HomeActivity"
        android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.HOME"/>
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
     </activity>
    

    This line is the relevant one (everything else is just an example):

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