ANDROID 隐藏 任务栏 systemui systembar 全屏显示

http://blog.csdn.net/xiao__ge/article/details/8662464 1015人阅读 评论(26) 收藏 举报

说说自己的经历吧:

(1)开始为了隐藏systemui利用过 kill com.android.systemui线程进行的隐藏,但是总有一个com.android.systemui.SystemUIService进行启动

我开始还是比较的坏的就弄了一个监听每500毫秒进行检测一次进行查杀

代码:

[java] view plain copy print ?
  1. @Override
  2. publicvoidonCreate(BundlesavedInstanceState){
  3. super.onCreate(savedInstanceState);
  4. setContentView(R.layout.main);
  5. ActivityManageram=(ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);//获得activity管理
  6. List<RunningAppProcessInfo>infos=am.getRunningAppProcesses();
  7. for(RunningAppProcessInforunningAppProcessInfo:infos){
  8. System.out.println("processName:====================:"+runningAppProcessInfo.processName);
  9. if(runningAppProcessInfo.processName.equals("com.android.systemui")){
  10. System.out.println("processpid:"+runningAppProcessInfo.pid);
  11. Stringstr="/system/bin/kill"+runningAppProcessInfo.pid;
  12. System.out.println("str:"+str);
  13. Processprocess;
  14. Runtimeruntime;
  15. try{
  16. runtime=Runtime.getRuntime();
  17. process=runtime.exec("su");
  18. System.out.println("01010101010");
  19. process=runtime.exec(str);
  20. intexitVal=process.waitFor();
  21. System.out.println("66666666666666666666666");
  22. break;
  23. }catch(IOExceptione){
  24. System.out.println(e);
  25. }catch(InterruptedExceptione){
  26. //TODOAuto-generatedcatchblock
  27. e.printStackTrace();
  28. }


(2)通过长时间研究我研究到了SystemUI.apk,我就就想对这个东西进行操作了。开始我删除掉后,systeui还是运行着,我就用kill命令直接杀掉这个线程,然后就开始报错了。说找不到SystemUI什么的。及其的烦人,不过重新启动就可以了。就没有那个错误了。

苍天真的不负有心人,本人找到一个更好的方法,原来大概是这样的:通过命令移除SystemUI.apk放到一个文件夹中,然后重新启动com.systemui.SystemUIService这个服务

就可以了。如果想恢复就把SystemUI.apk移到/system/app/下并且重新启动com.systemui.SystemUIService这个服务

代码参照:

[java] view plain copy print ?
  1. FilesystemUIapkFile=newFile("/system/app/SystemUI.apk");
  2. @Override
  3. publicvoidonCreate(BundlesavedInstanceState){
  4. super.onCreate(savedInstanceState);
  5. setContentView(R.layout.main);
  6. finalToggleButtonsystemBarToggleButton=(ToggleButton)findViewById(R.id.systemBarToggleButton);
  7. systemBarToggleButton.setChecked(systemUIapkFile.exists());
  8. systemBarToggleButton.setOnCheckedChangeListener(newOnCheckedChangeListener(){
  9. @Override
  10. publicvoidonCheckedChanged(CompoundButtonbuttonView,booleanisChecked){
  11. systemBarToggleButton.setChecked(isChecked);
  12. switchSystemUI();
  13. if(isChecked){
  14. Intentintent=newIntent();
  15. intent.setComponent(newComponentName(
  16. "com.android.systemui",
  17. "com.android.systemui.SystemUIService"));
  18. startService(intent);
  19. }
  20. }
  21. });
  22. }
  23. privatevoidswitchSystemUI(){
  24. try{
  25. Processp;
  26. p=Runtime.getRuntime().exec("su");
  27. //Attempttowriteafiletoaroot-only
  28. DataOutputStreamos=newDataOutputStream(p.getOutputStream());
  29. os.writeBytes("mount-oremount,rw/dev/block/stl6/system\n");
  30. if(systemUIapkFile.exists()){
  31. os.writeBytes("mv/system/app/SystemUI.apk/system/SystemUI.apk\n");
  32. }else{
  33. os.writeBytes("mv/system/SystemUI.apk/system/app/SystemUI.apk\n");
  34. }
  35. os.writeBytes("mount-oremount,ro/dev/block/stl6/system\n");
  36. //Closetheterminal
  37. os.writeBytes("exit\n");
  38. os.flush();
  39. p.waitFor();
  40. }catch(Exceptione){
  41. ShowErrorGlobal(e);
  42. }
  43. }
  44. protectedvoidShowErrorGlobal(Exceptione){
  45. ByteArrayOutputStreambaos=newByteArrayOutputStream();
  46. PrintStreamstream=newPrintStream(baos);
  47. e.printStackTrace(stream);
  48. stream.flush();
  49. newAlertDialog.Builder(this)
  50. .setIconAttribute(android.R.attr.alertDialogIcon)
  51. .setTitle("Epicfail")
  52. .setMessage("Error:"+newString(baos.toByteArray())).show();
  53. }


(3)

这种更牛逼,什么还自己通过命令操作。都是也路子。人家google给咱提供的有接口直接用就行啊

直接代码参考吧:

[java] view plain copy print ?
  1. intflag=context.getWindow().getDecorView().getSystemUiVisibility();
  2. //intfullScreen=View.SYSTEM_UI_FLAG_SHOW_FULLSCREEN;
  3. intfullScreen=0x8;
  4. if(visible){
  5. if((flag&fullScreen)!=0){
  6. context.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
  7. }
  8. }else{
  9. if((flag&fullScreen)==0){
  10. context.getWindow().getDecorView().setSystemUiVisibility(flag|fullScreen);
  11. }
  12. }


如果有什么疑问可以留下,尽量解决。



点击打开链接

源码下载地址

更多相关文章

  1. 没有一行代码,「2020 新冠肺炎记忆」这个项目却登上了 GitHub 中
  2. GitHub 标星 2.5K+!教你通过玩游戏的方式学习 VIM!
  3. 如何在后台运行Linux命令?
  4. No.11 使用firewall配置的防火墙策略的生效模式
  5. android wifi ralink rt3070开发记录
  6. Handler Looper Message源码研究
  7. android 关于Canvas保存到本地图像
  8. 线程间通信----Handler
  9. Android实现关机重启的方法分享

随机推荐

  1. Android中一些错误
  2. 常用的android弹出对话框
  3. android之ListView与Adapter(结合JavaBea
  4. android日期控件显示
  5. android webview在弹出软键盘时,布局没有
  6. Android(安卓)md5加密
  7. android 录音 播放
  8. android解析xml的通用写法
  9. Android(安卓)DatePickerDialog存在执行
  10. Android(安卓)ApiDemos示例解析(178):Vie