Search code examples
javaandroidkiosk-mode

Removing Android navigation and topbar,


I am trying to implement a Kiosk app on a rooted android device, and I need to disable the navigation and status bar completely.

These commands works from adb shell

Disable:

service call activity 42 s16 com.android.systemui

Enable:

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

That's good! Now I need to be able to do it from my app. So to disable I've tried:

Process process = Runtime.getRuntime().exec("su service call activity 42 s16 com.android.systemui");

when pressing a button in my activity. But nothing happens, and no exceptions are thrown. A toast pops up though, saying that the app has been given super user rights.

Any ideas?


Solution

  • To run su cmd you can use this

    public static void runCmd(String cmd) {
        DataOutputStream os;
        try {
            Process process = Runtime.getRuntime().exec("su");
            os = new DataOutputStream(process.getOutputStream());
            os.writeBytes(cmd + "\n");
            os.writeBytes("exit\n");
            os.flush();
            os.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    

    To disable system ui you can run this command

    runCmd("pm disable com.android.systemui && service call activity 42 s16 com.android.systemui");
    

    If you want to enable back

    runCmd("pm enable com.android.systemui && am startservice -n com.android.systemui/.SystemUIService");