原文:http://blog.csdn.net/xiaogezq0/article/details/8662464
(1)开始为了隐藏systemui利用过 kill com.android.systemui线程进行的隐藏,但是总有一个com.android.systemui.SystemUIService进行启动
我开始还是比较的坏的就弄了一个监听每500毫秒进行检测一次进行查杀
代码:
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);// 获得activity管理
- List<RunningAppProcessInfo> infos = am.getRunningAppProcesses();
- for (RunningAppProcessInfo runningAppProcessInfo : infos) {
- System.out.println("processName:====================:"+runningAppProcessInfo.processName);
- if(runningAppProcessInfo.processName.equals("com.android.systemui")){
- System.out.println("processpid: "+runningAppProcessInfo.pid);
- String str = "/system/bin/kill "+runningAppProcessInfo.pid;
- System.out.println("str: "+str);
- Process process;
- Runtime runtime;
- try {
- runtime = Runtime.getRuntime();
- process = runtime.exec("su");
- System.out.println("01010101010");
- process = runtime.exec(str);
- int exitVal = process.waitFor();
- System.out.println("66666666666666666666666");
- break;
- } catch (IOException e) {
- System.out.println(e);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
(2)通过长时间研究我研究到了SystemUI.apk,我就就想对这个东西进行操作了。开始我删除掉后,systeui还是运行着,我就用kill命令直接杀掉这个线程,然后就开始报错了。说找不到SystemUI什么的。及其的烦人,不过重新启动就可以了。就没有那个错误了。
苍天真的不负有心人,本人找到一个更好的方法,原来大概是这样的:通过命令移除SystemUI.apk放到一个文件夹中,然后重新启动com.systemui.SystemUIService这个服务
就可以了。如果想恢复就把SystemUI.apk移到/system/app/下并且重新启动com.systemui.SystemUIService这个服务
代码参照:
- File systemUIapkFile = new File("/system/app/SystemUI.apk");
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- final ToggleButton systemBarToggleButton = (ToggleButton) findViewById(R.id.systemBarToggleButton);
- systemBarToggleButton.setChecked(systemUIapkFile.exists());
- systemBarToggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- systemBarToggleButton.setChecked(isChecked);
- switchSystemUI();
- if (isChecked) {
- Intent intent = new Intent();
- intent.setComponent(new ComponentName(
- "com.android.systemui",
- "com.android.systemui.SystemUIService"));
- startService(intent);
- }
- }
- });
- }
- private void switchSystemUI() {
- try {
- Process p;
- p = Runtime.getRuntime().exec("su");
- // Attempt to write a file to a root-only
- DataOutputStream os = new DataOutputStream(p.getOutputStream());
- os.writeBytes("mount -o remount,rw /dev/block/stl6 /system\n");
- if (systemUIapkFile.exists()) {
- os.writeBytes("mv /system/app/SystemUI.apk /system/SystemUI.apk\n");
- }else {
- os.writeBytes("mv /system/SystemUI.apk /system/app/SystemUI.apk\n");
- }
- os.writeBytes("mount -o remount,ro /dev/block/stl6 /system\n");
- // Close the terminal
- os.writeBytes("exit\n");
- os.flush();
- p.waitFor();
- } catch (Exception e) {
- ShowErrorGlobal(e);
- }
- }
- protected void ShowErrorGlobal(Exception e) {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream stream = new PrintStream(baos);
- e.printStackTrace(stream);
- stream.flush();
- new AlertDialog.Builder(this)
- .setIconAttribute(android.R.attr.alertDialogIcon)
- .setTitle("Epic fail")
- .setMessage("Error: " + new String(baos.toByteArray())).show();
- }
(3)
这种更牛逼,什么还自己通过命令操作。都是也路子。人家google给咱提供的有接口直接用就行啊
直接代码参考吧:
- int flag = context.getWindow().getDecorView().getSystemUiVisibility();
- // int fullScreen = View.SYSTEM_UI_FLAG_SHOW_FULLSCREEN;
- int fullScreen = 0x8;
- if(visible) {
- if((flag & fullScreen) != 0) {
- context.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
- }
- } else {
- if((flag & fullScreen) == 0) {
- context.getWindow().getDecorView().setSystemUiVisibility(flag | fullScreen);
- }
- }
补充:
网上搜罗了相应的资料,好像4.1有个SYSTEM_UI_FLAG_HIDE_NAVIGATION可以处理System Bar的隐藏,不管我在代码里面如何设置,就是不见效果,怀疑是手机上面的功能块吧,没得4.1的实体手机,就不具体深究。网上有些工具软件对其处理,有的需要Root权限,有的只是移动SystemUI软件包位置作消显,感觉不实用,查看View.java的源码,发现还有个标志位SYSTEM_UI_FLAG_SHOW_FULLSCREEN,实践了一会,预期的效果就出来了。
关键代码:
/**
* 设置系统栏可见性
*/
public static void setSystemBarVisible(final Activity context,boolean visible) {
int flag = context.getWindow().getDecorView().getSystemUiVisibility(); // 获取当前SystemUI显示状态
// int fullScreen = View.SYSTEM_UI_FLAG_SHOW_FULLSCREEN;
int fullScreen = 0x8; // 4.1 View.java的源码里面隐藏的常量SYSTEM_UI_FLAG_SHOW_FULLSCREEN,其实Eclipse里面也可以调用系统隐藏接口,重新提取下android.jar,这里就不述了。
if(visible) { // 显示系统栏
if((flag & fullScreen) != 0) { // flag标志位中已经拥有全屏标志SYSTEM_UI_FLAG_SHOW_FULLSCREEN
context.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); // 显示系统栏
}
} else { // 隐藏系统栏
if((flag & fullScreen) == 0) { // flag标志位中不存在全屏标志SYSTEM_UI_FLAG_SHOW_FULLSCREEN
context.getWindow().getDecorView().setSystemUiVisibility(flag | fullScreen); // 把全屏标志位加进去
}
}
}
这里多加了判断的方法,供调用
/**
* 判断状态栏是否显示
*/
public static boolean isSystemBarVisible(final Activity context) {
int flag = context.getWindow().getDecorView().getSystemUiVisibility();
// return (flag & View.SYSTEM_UI_FLAG_SHOW_FULLSCREEN) != 0;
return (flag & 0x8) == 0;
}