我有一个
Android Jelly Bean平板电脑已经扎根并且试图运行一个应用程序,其中包含隐藏系统栏的代码,但它没有被隐藏,任何人都可以帮助我解决这个问题.
public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button hide=(Button)findViewById(R.id.button1); Button show=(Button)findViewById(R.id.button2); hide.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Log.v("ds","hideSystembar"); try { Process proc = Runtime.getRuntime().exec(new String[]{ "su","-c","service call activity 79 s16 com.android.systemUI"}); proc.waitFor(); } catch (Exception e) { e.printStackTrace(); } } }); show.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Log.v("f","showSystembar"); try { Process proc = Runtime.getRuntime().exec(new String[]{ "am","startservice","-n","com.android.systemUI/.systemUIService"}); proc.waitFor(); } catch (Exception e) { e.printStackTrace(); } } }); } }
虽然我正在获得许可的祝酒:
超级用户日志屏幕截图:
解决方法
当引入ICS时,systemUI类的进程ID从79更改为42.下面的代码适用于您的应用可能正在运行的任何Android版本.
//HIDE TOOLBAR 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","service call activity "+ ProcID +" s16 com.android.systemUI"}); //WAS 79 proc.waitFor(); }catch(Exception ex){ Toast.makeText(getApplicationContext(),ex.getMessage(),Toast.LENGTH_LONG).show(); }