I am able to disable the System bar using the following adb command using a terminal client:
adb shell service call activity 42 s16 com.android.systemui
However, I want to achieve this programatically. I looked up how to execute adb commands programatically and found below code:
Process process = Runtime.getRuntime().exec("your command");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
I replaced "your command" with my adb command above but it does not disable the system bar. How can I achieve this?
You will need root access to do this from an app because ADB can access /system/bin/service but your app cannot (see GID of app and ADB).
Process su = null;
try {
su = Runtime.getRuntime().exec("su");
String cmd = "service call activity 42 s16 com.android.systemui\n";
su.getOutputStream().write(cmd.getBytes());
String exit = "exit\n";
su.getOutputStream().write(exit.getBytes());
su.waitFor();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (su != null) {
su.destroy();
}
}
You should also check out third party libraries for handling su commands: https://android-arsenal.com/details/1/451