Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to disable home button in android?

Tags:

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 == KeyEvent.KEYCODE_HOME)) {
            Toast.makeText(this, "You pressed the home button!",
                    Toast.LENGTH_LONG).show();
            return false;
        }
        return super.onKeyDown(keyCode, event);
    }

     @Override
     protected void onNewIntent(Intent intent) {
     super.onNewIntent(intent);
     if (Intent.ACTION_MAIN.equals(intent.getAction())) {
     Log.i("MyLauncher", "onNewIntent: HOME Key");

     }
     }
like image 771
love light Avatar asked Jun 19 '13 06:06

love light


People also ask

How do I disable my home button?

Go to Settings > Accessibility > Touch, then select AssistiveTouch to turn it off.

How do I bypass the home button on Android?

This example demonstrates how do I in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.

How do I change the home button settings?

Tap the Home Button > touch and hold the Recent Apps Button > Settings > Display > Home touch buttons. Select the modification you want to change. Tap Button combination to select which Home Touch Buttons you want in the bar and their location within the bar.


2 Answers

I think this can be done in another style if suits your requirement. By creating your activity as home activity. If you want to disable home button and show your custom application activity as launcher when home button is pressed. Just add these lines in manifest for that activity for which you want your launcher.

<activity
            android:name="com.example.TempActivity"
            android:clearTaskOnLaunch="true"
            android:excludeFromRecents="true"
            android:launchMode="singleTask"
            android:screenOrientation="landscape"
            android:stateNotNeeded="true" >
             <intent-filter >
                <action android:name="android.intent.action.MAIN" />

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

            </intent-filter>
</activity>

After adding and run your application. if user presses the home button, Android will ask for which launcher you want your home. Then your have to select your application launcher ALWAYS not ONLY ONCE.

if you want fully disable the user, so that he cant move to another screen then set theme to fullscreen with NoTitlebar.

like image 121
droidd Avatar answered Oct 05 '22 02:10

droidd


You can use Android-HomeKey-Locker to disable HOME KEY and other system keys(such as BACK KEY and MENU KEY)

NOTE

It seems that the solution only works on devices with hard home key

Hope this will help you in your application. Thanks.

like image 22
shaobin0604 Avatar answered Oct 05 '22 01:10

shaobin0604