Android app fullscreen problem

Hello,

I have a project that runs on Android, iOS and desktop. The same code is driving the display resolution for all platforms:

        int width = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
        int height = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;

The game looks good on both iOS and desktop, but when running on Android devices (Galaxy S6 edge and S10), the top part of the screen are not used for rendering, it is filled with whatever color is passed to the graphicsDevice.Clear() method.

Also, the GraphicsAdapter.DefaultAdapter.SupportedDisplayModes() calls returns only one resolution, 1920x1008, which is quite strange and explains the top part of the screen.

What method should I use instead of the above to get proper full screen?
If I just simply not set anything, leaving everything on default, then I have a similar line on the side of the screen…

Thanks

I think you need to use immersive mode and hide the system UI… maybe? Put these things in your GameActivity.cs file (or whatever you call your Android entry point.

protected override void OnResume()
{
	base.OnResume();

	// When we resume (which also seems to happen on startup), hide the system UI to go to full screen mode.
	HideSystemUI();
}

private void HideSystemUI()
{
	// Apparently for Android OS Kitkat and higher, you can set a full screen mode. Why this isn't on by default, or some kind
	// of simple switch, is beyond me.
	// Got this from the following forum post: http://community.monogame.net/t/blocking-the-menu-bar-from-appearing/1021/2
	if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
	{
		View decorView = Window.DecorView;
		var uiOptions = (int)decorView.SystemUiVisibility;
		var newUiOptions = (int)uiOptions;

		newUiOptions |= (int)SystemUiFlags.LowProfile;
		newUiOptions |= (int)SystemUiFlags.Fullscreen;
		newUiOptions |= (int)SystemUiFlags.HideNavigation;
		newUiOptions |= (int)SystemUiFlags.ImmersiveSticky;

		decorView.SystemUiVisibility = (StatusBarVisibility)newUiOptions;

		this.Immersive = true;
	}
}

I just copy/pasted this out of my project haha, so you get the exasperated comment I left from 2017 in there too :stuck_out_tongue: The link in the comment also tells you how to get the real size of the display, which you can then pass to your own screen manager so it knows what your screen size is.

1 Like

Yes, finally!
I’ve been messing with this for a week now, thank you!

1 Like

hahahaha yeah that’s def a Samsung Edge… Cracked corners, stupid vertical purple lines, odd resolution… I hated those damn phones :rofl:

Wasn’t the S10 the one that was prone to exploding?

Yes, the line appeared the moment I dropped it for the first time :smiley: luckily it’s nothing but a test phone for some years now, but my girlfriend’s s10 actually holds up really well even today!
I have switched to iphones for a few years now, although I have my fair share of problems with it as a user…

Okay I’m gonna go crazy. This solution worked for one phone (galaxy s6), but it still doesn’t work on s10 and s20… I added the code from the comment url to get the real display size, but it still doesn’t work properly on these two phones. Do you have any guess what might still be missing?

Using hacks and workarounds will not work.
this is a flaw with the android implementation of MonoGame.
you need to build monogame and build from source after fixing all the issues.

Actually I was able to solve it.
Using the code above provided by Trinith + adding the following code into my main loop solved the issue:

    protected void FixedUpdate()
    {
        if (GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width != VideoConfiguration.RESOLUTION_WIDTH || GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height != VideoConfiguration.RESOLUTION_HEIGHT)
        {
            graphics.PreferredBackBufferWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
            graphics.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
            VideoConfiguration.RESOLUTION_WIDTH = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
            VideoConfiguration.RESOLUTION_HEIGHT = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
            graphics.ApplyChanges();
        }
    }