3

我遇到了 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

3 回答 3

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();
    }
于 2013-02-27T09:54:56.753 回答
4

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

于 2013-02-27T10:12:13.990 回答
2

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();
}

您可以使用类似的节目。

于 2015-03-22T15:39:36.420 回答