Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova - StatusBar hidden at launch - Android

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

like image 277
Sahil Khanna Avatar asked Oct 06 '16 11:10

Sahil Khanna


1 Answers

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.

like image 139
Akhirul Fajar Avatar answered Nov 19 '22 08:11

Akhirul Fajar