Search code examples
androidandroid-launcherandroid-homebutton

Override Home Button Android


I'm programming an app that must stay on the screen of a tablet which is accessible by everyone.

This means that only people who know the passcode can access the tablet, while passing-by users can only use the app. However, I'm stuck on the home button. Is there any way to change it? Disable, control, anything?


Solution

  • You can make your application as a Home screen launcher app using very similar activity code in your AndroidManifest. This way when user press the home button your app will be opened.

        <activity
            android:name=".MainActivity"
            android:launchMode="singleTask"
            android:excludeFromRecents="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <!-- The following two intent-filters are the key to set homescreen -->
                <category android:name="android.intent.category.HOME" />
                <category android:name="android.intent.category.DEFAULT" />
    
            </intent-filter>
        </activity>