androidshellandroid-studioterminalandroid-7.1-nougat

Send command to terminal on Android using Java


I'm new in Java and I don't know how can I send a terminal command by code. The device uses Android Nougat 7.1.2. What I need to do is send the following commands "su pm disable com.android.systemui" to the terminal after the user pressed a button. I need advice how to do that, I don't know if it's possible. Sorry for the dumb question.

Note: My original problem was to deactive permanently the nav bar and the notification bar in my system (I have root access) and this is the solution I have chosen.

Thanks for reading


Solution

  • 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();
        }
    }
    

    taken from HERE...

    btw. this isn't reliable way for disabling whole UI, Android may occasionally bring back systemui to life...