Android - 在4.2.2(Nexus 10)上显示/隐藏系统栏

时间:2013-02-26 17:58:16

标签: android root android-4.2-jelly-bean nexus-10

我遇到了Nexus 10 - 4.2.2的问题。我正在使用4.0.4在Galaxy Tab 10.1上测试下面的代码并且它工作正常:

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系统栏之后不会显示,只需隐藏。

3 个答案:

答案 0 :(得分: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();
    }

答案 1 :(得分:4)

我认为您不应该通过Runtime.exec()使用系统调用来获得该结果。 您应该查看FullscreenActivity模板中的代码(源代码放在<android-sdk-folder>/tools/templates/activities/FullscreenActivity/root中):这是一个完整的工作示例,演示如何以编程方式显示/隐藏系统栏(顶部和底部)以及它甚至支持API 13 +的动画。

答案 2 :(得分:2)

善意回答,但我们大多数人都不知道 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();
}

你可以使用类似的节目。