Is there a way to hide the system bar in Android 3.0? It's an internal device and I'm managing navigation
Asked Answered
H

11

32

In Android 2.3 and below, you could make an application full screen, and then "hijack" the menu/back/search buttons by just returning false onKeyDown()... and registering the app as a default home launcher application, that way, there's no way to exit the application.

In Android 3.0 (Honeycomb) the navigation buttons (System Bar) is always present, I'd like to hide it. Is it possible?

FYI, I am not publishing this application on the Android Market. This is an internal application for devices that are going to be used internally, I need to secure the device.

Humes answered 24/2, 2011 at 20:23 Comment(6)
I do like how you added the FYI just in case someone was gonna accuse you of hijacking Android devices. :)Leopardi
Yes, had to, I knew where the answer was going if I didn't add that part.Humes
Duplicate #5884289Kootenay
Not necessarily, and in any case, look at the difference in the dates when the questions were asked.Humes
If you think it's a duplicate, you misunderstood the question.Eventual
This is very old, but always comes up when looking to hide the nav bar, so I am including this from 4.4 which does it. developer.android.com/training/system-ui/immersive.htmlAndean
E
11

You cannot hide the system bar on Android 3.0.

Excusatory answered 24/2, 2011 at 22:44 Comment(9)
eep that kinda sucks? not even for video games or movies?Wheelock
Yeah this sucks badly. Previous Android iterations allowed me to give Android devices to employees and let them use my app and only my app. I even wrote a custom home screen launcher to deal with security and everything. This is a real set back for me and my company.Humes
You can put the system bar in "lights out" mode, where all the buttons and notifications are dimmed/hidden. You could go fullscreen before because devices had to have a hardware home button, it's not the case anymore. The user must be able to always hit home.Excusatory
I know that, but "lights out" only makes the buttons be temporarily invisible, does not disable them. Yes, the user has to be able to always hit home, but that's it. I solved that problem by declaring my own private application as a Default Home Launcher and home is hijacked too. This is basically taking away control from developers. I use Android devices to give them to employees and I run an internal private application on them, but I need to avoid them using anything else, before I could, now I can't do this.Humes
You realize that even on a phone the user can reboot in safe mode (hold down the Home key during boot) to disable all 3rd party apps (which means your apps) and run the standard apps/uninstall 3rd party apps? Android is designed to ensure that the user remains in control of his device.Excusatory
But shouldn't the 2.3 method work fine on 3.0 too. The system bar basically acts as the soft/hard buttons on a regular device. If you register your app as the default home they may be able to access settings via it but they should be pretty much looked in apart from that.Neslund
Count me as another developer very disappointed by this feature of Honeycomb. Our application is for children ages 2-8, and must provide a way to block navigation buttons that would exit to the normal Android environment - this is to prevent the child from running other applications, deleting items, or otherwise messing with the device by accident. (We give the parent a way to regain control of their device). "Lights out" mode isn't sufficient. I wish the Android team would give developers the tools we need to address use cases they haven't thought of, and trust us to do the right thing.Fasces
@RomainGuy, yes, I do realize that, however, the device is in a stand with a bracket and the power button is inaccessible. Believe me, the way it's setup on the kiosk, it's not possible to get into it unless it's my running app, and if for some reason the devices gets rebooted, it goes back into my own "home screen" (which is blocked as well) and that launches the proper app depending on the terminal type. The device is managed remotely.Humes
The loss of precious screen real estate is also an issue. I think there are too many bars on the screen: the notification bar, the action bar, the system bar. Please leave us some space for.. you know what: the app !Kania
H
31

Since this is not possible to do using a public API, I have found a way to do it in a very "hack-ish" way that requires a rooted device.

Update: as user864555 pointed below, this is another solution

$ adb remount
$ adb shell mv /system/app/SystemUI.odex /system/app/SystemUI.odexold
$ adb shell mv /system/app/SystemUI.apk /system/app/SystemUI.apkold
$ adb reboot

"That code disable the app SystemUI which is the actually menu bar. Which that modification, you will also gain the space of that system bar. But make sure to have a back button or something to exit."

That works great as well. Please vote for his answer. I will try to keep this one updated as much as I can.


Update: Here's a third method. A way to do it programmatically or using the command line. Found here: http://android.serverbox.ch/?p=306

This method requires root access, but you don't need to change the LCD Density, keeping the same as the original, and you can get the UI nav bar back really quick and easy without having to reboot everytime.

The blog post also shows how to implement it on your Android application, remember it requires root, and it might not be a great idea to do so unless your application is running on a kiosk or your own device, please do not implement this method on an app that's published in the Android market or anywhere public.

To stop/remove/disable the system bar (need to be su before issuing this command):

$ service call activity 79 s16 com.android.systemui

To restore the system bar just simply issue this command:

$ am startservice -n com.android.systemui/.SystemUIService

It's that easy. Hopefully ICS gets released soon along with the source code so that anyone can build Android for our Kiosk tablets.

Humes answered 10/5, 2011 at 20:54 Comment(3)
I couldn't find ro.sf.lcd_density=240 in my build.prop (Acer Iconia A500 tab rooted with Samsung galaxy 10.1 Rom). For the second method, also couldn't locate SystemUI.odex (honeycomb). Just renamed the SystemUI.apk and it seems to be working, thank you.Betook
That works just fine as long as your build is deodexed, and that's the case on your end. You might also want to restore that and checkout this app: market.android.com/details?id=com.tlalexander.tabletbarhider (not mine, but it uses the last method I posted above)Humes
the service call and the file name change make it impossible to receive calls (atleast on samsung fame)Sugden
E
11

You cannot hide the system bar on Android 3.0.

Excusatory answered 24/2, 2011 at 22:44 Comment(9)
eep that kinda sucks? not even for video games or movies?Wheelock
Yeah this sucks badly. Previous Android iterations allowed me to give Android devices to employees and let them use my app and only my app. I even wrote a custom home screen launcher to deal with security and everything. This is a real set back for me and my company.Humes
You can put the system bar in "lights out" mode, where all the buttons and notifications are dimmed/hidden. You could go fullscreen before because devices had to have a hardware home button, it's not the case anymore. The user must be able to always hit home.Excusatory
I know that, but "lights out" only makes the buttons be temporarily invisible, does not disable them. Yes, the user has to be able to always hit home, but that's it. I solved that problem by declaring my own private application as a Default Home Launcher and home is hijacked too. This is basically taking away control from developers. I use Android devices to give them to employees and I run an internal private application on them, but I need to avoid them using anything else, before I could, now I can't do this.Humes
You realize that even on a phone the user can reboot in safe mode (hold down the Home key during boot) to disable all 3rd party apps (which means your apps) and run the standard apps/uninstall 3rd party apps? Android is designed to ensure that the user remains in control of his device.Excusatory
But shouldn't the 2.3 method work fine on 3.0 too. The system bar basically acts as the soft/hard buttons on a regular device. If you register your app as the default home they may be able to access settings via it but they should be pretty much looked in apart from that.Neslund
Count me as another developer very disappointed by this feature of Honeycomb. Our application is for children ages 2-8, and must provide a way to block navigation buttons that would exit to the normal Android environment - this is to prevent the child from running other applications, deleting items, or otherwise messing with the device by accident. (We give the parent a way to regain control of their device). "Lights out" mode isn't sufficient. I wish the Android team would give developers the tools we need to address use cases they haven't thought of, and trust us to do the right thing.Fasces
@RomainGuy, yes, I do realize that, however, the device is in a stand with a bracket and the power button is inaccessible. Believe me, the way it's setup on the kiosk, it's not possible to get into it unless it's my running app, and if for some reason the devices gets rebooted, it goes back into my own "home screen" (which is blocked as well) and that launches the proper app depending on the terminal type. The device is managed remotely.Humes
The loss of precious screen real estate is also an issue. I think there are too many bars on the screen: the notification bar, the action bar, the system bar. Please leave us some space for.. you know what: the app !Kania
B
7

If you have access to system file, you can do this (mine is unlocked and rooted, so i'm not sure what you need, I haven't tried with a factory fresh xoom):

adb shell
cd /system/app/
mv SystemUI.odex SystemUI.odexold
mv SystemUI.apk SystemUI.apkold
exit
adb reboot

That code disable the app SystemUI which is the actually menu bar. With that modification, you will also gain the space of that system bar, but make sure that you have a back button or something to exit in your app.

Edit:

If you have problems with read-only file, you mint need to mount the /system directory as read-write. To do so, use this command in adb shell (Source: http://forum.xda-developers.com/showthread.php?t=1159495&page=5)

mount -o remount,rw /dev/block/stl6 /system

You can remount it as read-only using that command:

mount -o remount,ro /dev/block/stl6 /system

Edit:

This methods allow the soft keyboard to be displayed normally when needed.

Before answered 29/7, 2011 at 8:59 Comment(3)
Sweet, I think this might be a better solution IMHO. Thanks.Humes
Yea, it's perfect for a kiosk mode and I don't think you can use this to make a malicious program. So it's very nice.Before
Agreed. Hey, before adb shell you can do adb remount and then you dont need to mount -rw manually, its also device agnostic ;)Humes
B
1

Here is related code with my previous answer. It automatically hide the status bar and show it back again when finish. Important: to show it back again, the code have to restart system_server which take some time to boot again and during that time, you will see the honeycomb booting animation. That's the only I find for now to show the statusbar again. Restarting SystemUI is not enought. And because of that, it will shutdown your app when restart system_server.

This code need a rooted os with superuser installed on.

package com.projects;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TableLayout.LayoutParams;

// http://www.stealthcopter.com/blog/2010/01/android-requesting-root-access-in-your-app/
public class FullScreenTestActivity extends Activity implements Button.OnClickListener {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        try
        {
            Process p;
            p = Runtime.getRuntime().exec("su"); 

            // Attempt to write a file to a root-only
            DataOutputStream os = new DataOutputStream(p.getOutputStream());
            os.writeBytes("mount -o remount,rw /dev/block/stl6 /system\n");
            os.writeBytes("mv /system/app/SystemUI.odex /system/app/SystemUI_Old.odex\n");
            os.writeBytes("mv /system/app/SystemUI.apk /system/app/SystemUI_Old.apk\n");
            os.writeBytes("mount -o remount,ro /dev/block/stl6 /system\n");

            // Close the terminal
            os.writeBytes("exit\n");
            os.flush();
            p.waitFor();

            new AlertDialog.Builder(this)
                .setIconAttribute(android.R.attr.alertDialogIcon)
                .setMessage("Android Honeycomb StatusBar removed successfully!")
                .show();

            // Set action for exiting.
            Button cmdExit = new Button(this);
            cmdExit.setText("Exit");
            cmdExit.setOnClickListener(this);
            this.addContentView(cmdExit, new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
        }
        catch (Exception e)
        {
            ShowErrorGlobal(e);
        }
    }

    public void onClick(View v) {
        try
        {
            Process p;
            p = Runtime.getRuntime().exec("su"); 

            // Attempt to write a file to a root-only
            DataOutputStream os = new DataOutputStream(p.getOutputStream());
            os.writeBytes("mount -o remount,rw /dev/block/stl6 /system\n");
            os.writeBytes("mv /system/app/SystemUI_Old.odex /system/app/SystemUI.odex\n");
            os.writeBytes("mv /system/app/SystemUI_Old.apk /system/app/SystemUI.apk\n");
            os.writeBytes("mount -o remount,ro /dev/block/stl6 /system\n");
            String systemServerPID = GetSystemServerPID();
            if (systemServerPID != null)
                os.writeBytes("kill " + systemServerPID + "\n");
            // else ... manual reboot is required if systemServerPID fail.

            // Close the terminal
            os.writeBytes("exit\n");
            os.flush();
            p.waitFor();
        }
        catch (Exception e)
        {
            ShowErrorGlobal(e);
        }
    }

    public String GetSystemServerPID()
    {
        try
        {
            Process p = Runtime.getRuntime().exec("ps -n system_server"); 
            p.waitFor();

            BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
            reader.readLine(); // Skip header.
            return reader.readLine().substring(10, 16).trim();
        }
        catch (Exception e)
        {
            return null;
        }
    }

    protected void ShowErrorGlobal(Exception e)
    {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PrintStream stream = new PrintStream( baos );
        e.printStackTrace(stream);
        stream.flush();

        new AlertDialog.Builder(this)
            .setIconAttribute(android.R.attr.alertDialogIcon)
            .setTitle("Epic fail")
            .setMessage("Error: " + new String( baos.toByteArray() ))
            .show();
    }
}
Before answered 29/7, 2011 at 21:58 Comment(1)
What else, if anything does the System Server do? What are the ramifications of disabling it? Thanks SHedger
R
0

Although this doesn't answer the question of 'locking' the screen, you can hide the status bar without being root by using the setSystemUiVisibillity api(API level 11).

Some pseudocode:

public MyActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstance) {
        //...
        final View mainView = findViewById(R.id.you_main_view_id);
        mainView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);

        //Register a listener for when the status bar is shown/hidden:
        final Context context = getApplicationContext();
        mainView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener () {
            @Override
            public void onSystemUiVisibilityChange(int visibility) {
                if ((visibility == View.SYSTEM_UI_FLAG_VISIBLE)) {
                    //Do stuff here...pause the video/game?
                } else {
                    //Do other stuff here..resume the video/game?
                }
            }
        });
    }
}

This will hide the status bar until the user clicks along the lower edge of the screen, in which case the status bar will get shown (it'll get hidden again after a few seconds).

Make sure you've specified targetSdkVersion="11" or higher in your manifest.

Regardless answered 8/12, 2011 at 21:27 Comment(0)
L
0

The application HideBar can be used to hide the system bar on android tablets (HC, ICS, JB). It contains an optional kiosk mode that can be used to lock down tablets completely and also other options like a hidden back button. It is GPL software. Contact the developer (me, see email on applications website) if this application has to be installed in large volumes.

Lheureux answered 31/7, 2012 at 10:51 Comment(2)
Your link says it hides the STATUS bar. The OP was asking about the SYSTEM bar.Hedy
@Hedy You are right. It should be systembar. I'll update the website to mention systembar in stead of statusbar. The latest version of the program has already been corrected.Lheureux
A
0

For others who have had this problem:

If you haven't set the android:targetSdkVersion properly in your AndroidManaifest.xml file, setSystemUiVisibility has no effect (unlike other advanced APIs which work whether or not the targetSDKVersion has been set properly or not).

I had accidentally left my targetSdkVersion at 8. Bumping it up to 16 immediately caused setSystemUIVisiblity to have the desired effect.

Annia answered 8/10, 2012 at 22:7 Comment(0)
M
0

Yes it is possible to do if you have root access on the device.

This code can hide and show the StatusBar by killing it`s proccess and calling it back again.

package com.example.statusbar;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

public class MainActivity extends Activity {

    String commandToExecute;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);

        commandToExecute = "/system/xbin/su";
        executeShellCommand(commandToExecute);

        Button btHideStatusBar = (Button) findViewById(R.id.buttonHide);
        Button btShowStatusBar = (Button) findViewById(R.id.buttonShow);


        btHideStatusBar.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                commandToExecute = "/system/xbin/su -c /system/bin/service call activity 42 s16 com.android.systemui";
                executeShellCommand(commandToExecute);

            }
        });

    btShowStatusBar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {

            commandToExecute = "/system/xbin/su -c /system/bin/am startservice -n com.android.systemui/.SystemUIService";
            executeShellCommand(commandToExecute);

        }
    });

    }

    private boolean executeShellCommand(String command) {
        try {

            Runtime.getRuntime().exec(command);

            return true;
        } catch (Exception e) {
            return false;

        }
    }


}
Massimiliano answered 10/12, 2014 at 18:14 Comment(0)
A
0

As of 4.4 you can do this (this question is very old, but always comes up on this topic):

setSystemUiVisibility(View.SYSTEM_UI_FLAG_IMMERSIVE)

https://developer.android.com/training/system-ui/immersive.html

Andean answered 3/2, 2015 at 2:11 Comment(0)
C
-1

if you want to hide navigation bar through out the application then here is the most simplest way. just write this code in your application tag in manifest file

> <Application
> android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" <!--
> other parameters of application tag-->
> >
Canaliculus answered 26/3, 2013 at 6:42 Comment(0)
I
-1

android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen

or

mainView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE)

No, the task bar is still there, with three gray dots instead classic icons

Incondensable answered 30/3, 2013 at 1:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.