Android - Show/Hide system bar on 4.2.2 (Nexus 10)

goodm picture goodm · Feb 26, 2013 · Viewed 11.3k times · Source

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.

Answer

goodm picture goodm · Feb 27, 2013

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