15

I have a kiosk mode application which hides all traces of the System UI (Notification bar and navigation buttons). On versions of Android pre-Lollipop the following works fine (as root):

service call activity 42 s16 com.android.systemui

In Lollipop however, this makes the screen completely black as well as hiding the System UI. For this reason it cannot be used.

Does anyone know of a workaround for this?

I have tried the Device Owner/Admin solution for Screen Pinning, but unfortunately this is not acceptable because it does not hide the System UI entirely, but leaves the back button visible when swiping form the bottom of the screen.

Nova Entropy
  • 5,727
  • 1
  • 19
  • 32
  • This is far from a perfect solution, but one thing you can do is at least disable the back button (intercept the onBackPressed() method in your activity), to make sure the user can not leave your app in that way. – Jeffrey Klardie Feb 12 '15 at 16:22
  • Yes, I do that too, for devices with physical buttons; but for our particular branding/kiosk mode, there must be no System UI at all visible. – Nova Entropy Feb 12 '15 at 16:25

5 Answers5

9

If the device is rooted you could disable the systemui pm disable-user com.android.systemui and then the device-owner method works fine.

This method should not be used if the device runs other apps, because if your app crashes the systemui might be disabled and the user can't interact with the device.

<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
&device-owner package="com.mycompany" name="*mycompany" />
Mark
  • 7,507
  • 12
  • 52
  • 88
  • 1
    This is in fact how I worked around the problem, except that I used `pm disable com.android.systemui` and didn't need to use the device owner as my app is the only home app on the device. – Nova Entropy Feb 13 '15 at 09:29
  • Yea you don't wanna use this service, it may take your device to unstable states if your app go to crashes. Did you take a look on the fullscreen mode ? – JoJoPla Feb 17 '15 at 09:15
  • @tristan2468, I am using the same call "service call activity 42 s16 com.android.systemui" in my app and get the black screen on android 5.0. I tried ```pm disable com.android.systemui``` but that does nothing on my device. Did you end up using a combination of these commands on 5.0 ? and yes my device is rooted. – Punit Raizada Jul 02 '15 at 21:21
  • Thanks, you saved my day. Tried with shell commands, init.rc edit but only this works on my kiosk mode android! – Seraphim's Oct 25 '16 at 19:05
2

I have used set following setup to get rid of System UI in Android Marshmallow

final int flags = 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;

and OnCreate i have

this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_instructions);
getWindow().getDecorView().setSystemUiVisibility(flags);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

Then i have added code to hide back key if user swipes top or bottom screen.

/* Hides Navigation bar again if user swipes it visible */
@Override
protected void onResume() {
        getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(
                new View.OnSystemUiVisibilityChangeListener() {
                    @Override
                    public void onSystemUiVisibilityChange(int visibility) {
                    getWindow().getDecorView().setSystemUiVisibility(flags);
                    }
                });
    super.onResume();
    Log.i(TAG,"Activity Life Cycle : onResume : MainActivity Resumed");
}

This will show back key briefly in screen and hides it back. Only problem in this is that if you open new Activity on top of Pinned activity. It doesn't get any onResume indications.

Juge
  • 536
  • 8
  • 21
0

I was having the same issue. This code will work for 4.4 and Lollipop (Tested). Should work on other versions too.

 /**
     * Uses Root access to enable and disable SystemUI.
     * @param enabled Decide whether to enable or disable.
     */
    public void setSystemUIEnabled(boolean enabled){
        try {
            Process p = Runtime.getRuntime().exec("su");
            DataOutputStream os = new DataOutputStream(p.getOutputStream());
            os.writeBytes("pm " + (enabled ? "enable" : "disable")
                    + " com.android.systemui\n");
            os.writeBytes("exit\n");
            os.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

Of course it requires root

AhmedW
  • 536
  • 2
  • 5
  • 21
0

I found this other solution and it's works on android 5.0

private void hideNavigationBar(){
        try {
            Process process = Runtime.getRuntime().exec("su");
            DataOutputStream os = new DataOutputStream(process.getOutputStream());
            os.writeBytes("pm disable com.android.systemui\n");
            os.flush();
            os.writeBytes("exit\n");
            os.flush();
            process.waitFor();
            //////////////////////////////////////
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
garatu
  • 350
  • 3
  • 13
-1

You probably wanna use the 'Immersive mode'. You'll find all the needed information here

You have an example here, for every versions of Android !

Ektos974
  • 999
  • 10
  • 30
  • Immersive mode isn't enough for my particular use-case. It is designed to allow an application to go into a psuedo-fullscreen mode, but the user is always able to show the System UI just be touching near the top or bottom of the screen. This is not enough for a full kiosk mode. – Nova Entropy Feb 17 '15 at 09:52