3

I got issue with Nexus 10 - 4.2.2. I was testing code below on Galaxy Tab 10.1 with 4.0.4 and it was working fine:

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

But on Nexus 10 system bar won't show after, just hide.

faceman
  • 1,318
  • 11
  • 20
goodm
  • 7,275
  • 6
  • 31
  • 55

3 Answers3

10

To show and hide the system bar and notification bar on 4.2.2 and others:

Hide:

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

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();
    }
goodm
  • 7,275
  • 6
  • 31
  • 55
4

I think you should not use system calls via Runtime.exec() to get that result. You should look at the code in FullscreenActivity template (sources are placed in <android-sdk-folder>/tools/templates/activities/FullscreenActivity/root): that is a full working example showing how to show/hide system bars (both top and bottom one) programmatically, and it even supports animations for API 13+.

a.bertucci
  • 12,142
  • 2
  • 31
  • 32
  • Once updated, if you use Eclipse+ADT, you can use template wizard to generate that sample activity in your Android project: menu `File>New>Android>Android Object>Fullscreen Activity` – a.bertucci Feb 27 '13 at 11:20
  • Don't worry this step I can handle ;) – goodm Feb 27 '13 at 11:25
  • Sorry, maybe a little overeager, I know :) – a.bertucci Feb 27 '13 at 11:29
  • Only one disadvantage of using the temple is this that you have to override the volume buttons cause after every click bottom system bar come back and whatever you do, after long press on power, bottom bar came back. So in the end probably I will have to use my method, because this will be a kiosk app so I need to limit the user as much is possible. – goodm Feb 27 '13 at 12:16
2

Answer by goodm works fine, but most of us are not aware about envp

So here is full code:

HIDE

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

You can use similar for show.

jcaron
  • 17,302
  • 6
  • 32
  • 46
Bhupinder
  • 1,329
  • 1
  • 14
  • 29