8

I'm using Cordova's StatusBar and SplashScreen. I want the app to launch fullscreen i.e. status bar to be hidden when the app launches.

In the deviceready callback, I'm invoking StatusBar.hide() and later on I use StatusBar.show() to show the status bar again. This works fine.

The issue is when the splash image appears, the status bar is visible. And when the deviceready callback if fired, the status bar hides. I even tried setting Fullscreen preference in config.xml to true, but the result is same. Hide at Startup configuration is also related to iOS only.

Is there a way (using Cordova only) to launch the app without status bar and show it later on?

Note: I'm using SplashScreen plugin to show splash screen

Sahil Khanna
  • 4,262
  • 8
  • 47
  • 72

1 Answers1

1

Find MainActivity.java in

\platforms\android\app\src\main\java\com\yourpackage\name

add this to the import section :

import android.view.WindowManager;

then add this code to the last line :

public class MainActivity extends CordovaActivity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        // enable Cordova apps to be started in the background
        Bundle extras = getIntent().getExtras();
        if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
            moveTaskToBack(true);
        }
        // [Hyuck] add this two line below    
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

        // Set by <content src="index.html" /> in config.xml
        loadUrl(launchUrl);
    }

    // [Hyuck] onStart() is totally new.
    @Override
    public void onStart()
    {
        super.onStart();
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    }
}

this is snippet from Hyuck answer on : Ionic 3 - Hide status bar during splash screen show

it's do the job for me.

  • Have you used the opposite of this the prevent the jump (caused by statusBar) when returning from native view (camera or video) to webview? Where the status bar momentarily pushes down the webview? – user3919920 Jan 28 '20 at 23:06