I use the following code to disable the navigation bar and the status bar on my 4.4 nexus device
try {
proc = Runtime.getRuntime().exec(new String[] { "su", "-c", "service call activity 42 s16 com.android.systemui" });
} catch (Exception e) {
Log.w("Main","Failed to kill task bar (1).");
e.printStackTrace();
}
try {
proc.waitFor();
} catch (Exception e) {
Log.w("Main","Failed to kill task bar (2).");
e.printStackTrace();
}
Works like a charm. But when i try to do the same on My Nexus 7. The screen goes black and I can't see my Application activity.
Am I doing something wrong here? is the command different for android 5.0?
Both devices are rooted
Found the answer, the above code does not work on Lollipop. The below code will work on older and newer versions of Android (tested on 5.0 and 4.4).
private void systemUIEnabled(System.Boolean enabled){
try {
Java.Lang.Process process = Runtime.GetRuntime().Exec("su");
DataOutputStream os = new DataOutputStream(process.OutputStream);
os.WriteBytes("pm " + (enabled ? "enable" : "disable")
+ " com.android.systemui\n");
os.WriteBytes("exit\n");
Toast.MakeText (this, " UI Update , Post Reboot", ToastLength.Long).Show ();
os.Flush();
} catch (IOException e) {
e.PrintStackTrace();
Toast.MakeText (this, " UI Update , Error", ToastLength.Long).Show ();
}
}
Updated :
The above solution is C# for Xamarin. Below is the Java code
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();
}