Can I disable systemui From within my android app?

12,778
/**
 * 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
Share:
12,778

Related videos on Youtube

silversunhunter
Author by

silversunhunter

Updated on June 04, 2022

Comments

  • silversunhunter
    silversunhunter almost 2 years

    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?

    • silversunhunter
      silversunhunter about 9 years
      @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.
  • silversunhunter
    silversunhunter over 9 years
    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.
  • ByteHamster
    ByteHamster over 9 years
    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.
  • silversunhunter
    silversunhunter over 9 years
    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?
  • ByteHamster
    ByteHamster over 9 years
    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.
  • Amit Hooda
    Amit Hooda over 8 years
    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 ?