While developing a client survey app for a tablet I realized I have to disable the notification panel from being pulled & hide bottom navigation just in case, for all those funny clients out there trying to be a smart ***.
I am working with a non rooted device so using a reflection like in this answer isn't an option.
And while adding
getWindow().addFlags(WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY);
will do the trick, it will also disable everything else.
I started by requesting full screen for the app just to hide the top bar but this didn't do anything to the bottom navigation bar.
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Therefore I resorted to using Immersive Full-Screen Mode. It does hide both top and bottom bars but when the user swipes up or down, they appear again.
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
mDecorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
}
The device runs on Android 4.4
If I understood your problem, what you are looking for is a single purpose device and you can achieve what you want using the startLockTask()
function if the device is running Android 5 and higher as said here https://developer.android.com/work/cosu.html#emm-solutions
The device owner must include your app’s package(s) in setLockTaskPackages Sets the packages that can enter into lock task mode Needs to be set by the EMM You can call isLockTaskPermitted to verify that your package has been whitelisted by setLockTaskPackages. Your activity calls
startLockTask()
Requests to lock the user into the current task Prevents launching other apps, settings, and the Home button To exit, your activity must callstopLockTask()
Can only be called on an activity that’s previously calledstartLockTask()
Should be called when the app is user-facing betweenonResume()
andonPause()
It seems that you can achieve the same things on Android versions lower than 5 by using these actions as said here: http://www.andreas-schrade.de/2015/02/16/android-tutorial-how-to-create-a-kiosk-mode-in-android/
Overview
A Kiosk Mode is implemented by disabling various Android features that can be used to leave your app. The following features are affected:
- The back button
- The home button
- The recent apps button
- The power button
- The volume buttons