Search code examples
androidandroid-7.0-nougatbackground-serviceandroid-statusbar

Hide status bar with overlaying black bar


I have written an Android 7.0 application which collects sensor data in the background (using a background service). While the sensor recording is running I would like to hide the status bar (i.e. the Wifi symbol, clock etc.).

I thought about adding a black bar over the status bar while the background service is running. How can this be done?


Solution

  • you may hide the status bar via setSystemUiVisibility()

    View decorView = getWindow().getDecorView();
    int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
    decorView.setSystemUiVisibility(uiOptions);
    

    edit Please disregard this answer as this will only work for foreground application. For background application, as far as my limited knowledge, there is no way to set System-wide UI invisible.