9

I used this answer to achieve a Kiosk Mode for my app: https://stackoverflow.com/a/26013850

I rooted the tablet with Kingo Root and then performed the following commands:

adb shell >
 su >
 pm disable com.android.systemui >

I am building an app that will only be used on our devices as kiosks....

It works great BUT.. I would like to perform the disable and enable of the system ui from the Android application itself.

Are system commands possible from within an application?

3
  • Is it safe to disable com.android.systemui or can something bad happen on certain devices?
    – JohnyTex
    Commented Apr 20, 2015 at 14:54
  • 2
    @JohnyTex : This is a special case where I needed the users to NOT have the ability to do anything except use my app. The device was owned by my company and put into kiosks. Doing this made it almost impossible to exit whatever app you were in as there was no longer a home button, back button or notification drop down area. Commented Apr 22, 2015 at 19:09
  • I came to a situation where disabling systemui didn't help -it still ran even though disabled. See: android.stackexchange.com/questions/119508/… How can it run while being disabled?
    – JohnyTex
    Commented Aug 17, 2015 at 12:33

1 Answer 1

14
/**
 * 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();
    }
}

Works fine. Usage:

setSystemUIEnabled(true);  // Enable SystemUI
setSystemUIEnabled(false); // Disable SystemUI
5
  • I am about to try this but I have one question. Being that I am using a root software made for dummies(one click root access) I am wondering if there is a way for this class to know if it has root access or not. Commented Jan 20, 2015 at 21:32
  • 1
    You can use this function by calling setSystemUIEnabled(true); somewhere in your code. Just tested it, working fine. Determinung if there is root acces is explained here. Please accept this answer if it helped you. Commented Jan 20, 2015 at 21:40
  • This causes a restart of the device (hp 7 slate) Is this a device thing or is this expected on all devices as we are making a fundamental change to the OS? Commented Jan 20, 2015 at 22:23
  • Did it also restart when you typed in the command manually? It should behave exactly the same way as if you type in the command via adb. While testing, I have just disabled a user app instead of SystemUI so I can not verify the behavior. Commented Jan 21, 2015 at 16:12
  • hey this is not working for me i have a rooted nexus device and it has root access but the navigation buttons are still visible, when i try from terminal or from application ??? any suggestions ?
    – Amit Hooda
    Commented Dec 25, 2015 at 18:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.