需要root,不同的版本可能需要一定的修改
public static void showSystemBar(){
try {
Process proc = Runtime.getRuntime().exec("am startservice --user 0 -n com.android.systemui/.SystemUIService");
proc.waitFor();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void hideSystemBar(){
// 去掉系统栏
try{
//REQUIRES ROOT
Build.VERSION_CODES vc = new Build.VERSION_CODES();
Build.VERSION vr = new Build.VERSION();
String ProcID = "79"; //HONEYCOMB AND OLDER
//v.RELEASE //4.0.3
if(vr.SDK_INT >= vc.ICE_CREAM_SANDWICH){
ProcID = "42"; //ICS AND NEWER
}
//REQUIRES ROOT
Process proc = Runtime.getRuntime().exec(new String[]{"su","-c","service call activity "+ 42 +" s16 com.android.systemui"}); //WAS 79
proc.waitFor();
}catch(Exception ex){
// Toast.makeText(getApplicationContext(), ex.getMessage(), Toast.LENGTH_LONG).show();
}
}
public static void execHideSystemBarShell(){
String cmd="su -c service call activity 42 s16 com.android.systemui";
try{
//权限设置
Process p = Runtime.getRuntime().exec("su");
//获取输出流
OutputStream outputStream = p.getOutputStream();
DataOutputStream dataOutputStream=new DataOutputStream(outputStream);
//将命令写入
dataOutputStream.writeBytes(cmd);
//提交命令
dataOutputStream.flush();
//关闭流操作
dataOutputStream.close();
outputStream.close();
}
catch(Throwable t)
{
t.printStackTrace();
}
}