我的问题与Nexus 10的 - 4.2.2。 我在下面的Galaxy Tab 10.1与4.0.4测试代码,它是很好的工作:
try
{
Process proc = Runtime.getRuntime().exec(new String[]{"sh","startservice","-n","com.android.systemui/.SystemUIService"});
proc.waitFor();
}
catch (Exception e)
{
e.printStackTrace();
}
try
{
//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();
}
但是Nexus 10的系统栏上之后不会显示,只是隐藏。
为了显示和隐藏系统栏和通知栏4.2.2及其他:
隐藏:
try
{
String command;
command = "LD_LIBRARY_PATH=/vendor/lib:/system/lib service call activity 42 s16 com.android.systemui";
Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", command }, envp);
proc.waitFor();
}
catch(Exception ex)
{
Toast.makeText(getApplicationContext(), ex.getMessage(), Toast.LENGTH_LONG).show();
}
节目:
try
{
String command;
command = "LD_LIBRARY_PATH=/vendor/lib:/system/lib am startservice -n com.android.systemui/.SystemUIService";
Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", command }, envp);
proc.waitFor();
}
catch (Exception e)
{
e.printStackTrace();
}
我认为你不应该使用通过系统调用Runtime.exec()
来获取结果。 你应该看看在代码FullscreenActivity
模板(来源都放在<android-sdk-folder>/tools/templates/activities/FullscreenActivity/root
):这是显示如何显示/隐藏系统栏全工作示例(包括顶部和底部一个)程序,它甚至支持API 13+动画。
通过goodm回答工作得很好,但我们大多数人都没有意识到有关envp
因此,这里是完整的代码:
隐藏
try
{
String command;
command = "LD_LIBRARY_PATH=/vendor/lib:/system/lib service call activity 42 s16 com.android.systemui";
ArrayList<String> envlist = new ArrayList<String>();
Map<String, String> env = System.getenv();
for (String envName : env.keySet()) {
envlist.add(envName + "=" + env.get(envName));
}
String[] envp = (String[]) envlist.toArray(new String[0]);
Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", command }, envp);
proc.waitFor();
}
catch(Exception ex)
{
Toast.makeText(getApplicationContext(), ex.getMessage(), Toast.LENGTH_LONG).show();
}
您可以使用显示出类似的。