1

I can not disable home button and Which is next to it in android I tried this code but does not work

 @Override
public void onAttachedToWindow() {
    this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
    super.onAttachedToWindow();
}

Do you have any idea for solve this problem? Or Can I hide navigation bar permanently forever؟

Hazem
  • 342
  • 1
  • 5
  • 19
  • you want to hide the navigation bar permanently forever!? why would you want to do such a thing? you could go fullscreen and hide it while in fullscreen – lelloman Jun 14 '17 at 12:02
  • You can't in Android disable or completly hide the navigation bar. But you can set your app as kind of launcher, for example in this post: https://stackoverflow.com/a/27120660/5508719 – Julian Schmuckli Jun 14 '17 at 12:02
  • Beware that not allowing your users quit your app may make them a bit angry with you. – Alberto S. Jun 14 '17 at 12:06
  • there should be no way to do that. – Vladyslav Matviienko Jun 14 '17 at 12:46
  • @JulianSchmuckli thanks you saved my day – Hazem Jun 14 '17 at 13:12
  • for those who claim that this shouldn't be allowed at all: think of kiosk-applications. If you put a tablet in a shop for example - maybe for checking a price of an item via a barcode-scanner, your don't want your customers to terminate the app and have access to the underlying operating system. – Algoman Sep 19 '21 at 10:05

2 Answers2

4

Can I hide navigation bar permanently forever?

No, system would not allow you to do so. But you can prevent the app from exiting. Do the following in your onPause() method.

 @Override
    protected void onPause() {
        super.onPause();
        ActivityManager activityManager = (ActivityManager) getApplicationContext()
                .getSystemService(Context.ACTIVITY_SERVICE);
        activityManager.moveTaskToFront(getTaskId(), 0);
    }

You need the following permissions

<uses-permission android:name="android.permission.GET_TASKS"/>
<uses-permission android:name="android.permission.REORDER_TASKS" />
Darish
  • 11,032
  • 5
  • 50
  • 70
2

I found it. I took a part from here how to disable home button in android? and added one row Which originally existed LAUNCHER row as follow:

<activity android:name=".MainActivity"
        android:clearTaskOnLaunch="true"
        android:excludeFromRecents="true"
        android:launchMode="singleTask"
        android:screenOrientation="portrait"
        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" />
            <category android:name="android.intent.category.LAUNCHER"/>

        </intent-filter>
    </activity>
Hazem
  • 342
  • 1
  • 5
  • 19