1

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

I am looking for a way to completely disable them or (best case scenario) ask for a password before showing them again.

Alin
  • 1,218
  • 5
  • 21
  • 47

2 Answers2

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 call stopLockTask() Can only be called on an activity that’s previously called startLockTask() Should be called when the app is user-facing between onResume() and onPause()

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
regev avraham
  • 1,102
  • 1
  • 9
  • 24
  • Sounds just about right. I'm reading the guide right now and trying to figure our if their device supports lock task. I'll return with feedback. Thank you. – Alin Feb 24 '18 at 10:59
  • Apparently this was introduced since android 5 but the the device I am working on has android 4.4 on it. – Alin Feb 24 '18 at 11:08
  • Thank you! I am accepting your answer and awarding you the bounty cause of the link you posted! It really helped me a lot. I will add another answer with my complete solution. – Alin Mar 02 '18 at 21:11
  • Great! Thank you :-) – regev avraham Mar 03 '18 at 08:05
0

Probably more work than you want, but you could develop a custom launcher to prevent exiting the survey application, or immediately re-launch it on exit Launcher in this case being the default home screen and activity launching interface... That would at least work on lover versions of Android. I would expect it to be quite a lot of work though, especially to "plug" all the little get-arounds and holes that your users might find (getting into the settings etc)

C B J
  • 1,838
  • 16
  • 22