Hiding the System UI on Lollipop
Asked Answered
S

5

14

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.

Sonora answered 14/1, 2015 at 11:38 Comment(2)
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.Hermosillo
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.Sonora
C
8

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" />
Calathus answered 12/2, 2015 at 16:42 Comment(4)
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.Sonora
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 ?Doak
@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.Vic
Thanks, you saved my day. Tried with shell commands, init.rc edit but only this works on my kiosk mode android!Propene
B
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.

Baseman answered 18/5, 2017 at 9:6 Comment(0)
S
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

Scree answered 9/4, 2015 at 11:17 Comment(0)
G
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();
        }
    }
Ginaginder answered 6/4, 2016 at 22:32 Comment(1)
This is identical in functionality to the accepted answer.Sonora
C
-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 !

Christianchristiana answered 17/2, 2015 at 9:2 Comment(1)
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.Sonora

© 2022 - 2024 — McMap. All rights reserved.