Screen.height is not giving the proper resolution of an Android device when that device has a notch or navigation bar.

Due to this there is offset at bottom of screen:

Screenshot of banner close to the bottom of the screen

Here I have set the Admob banner to display at the bottom. But it shows with some offset away from the bottom edge of the screen.

How can I get the proper height of the device in Unity and work with the notch on devices that have them?

  • \$\begingroup\$ Your question is unclear. When you say Screen.height does not give proper resolution, do you mean it returns the space your game occupies and not the actual screen space? Because that's what supposed to happen, at least on android versions where the navigation bar is never minimised. Also you mention "Due to this, there is offset at the bottom of the screen". This does not make sense to me, are you saying that Unity produces a game that by default does not occupy the whole screen? \$\endgroup\$ – TomTsagk Dec 6 '18 at 11:29
  • \$\begingroup\$ I meant when i use Screen.height it give me 2156 but my screen resolution is 1080 X 2246. So i should get 2246 and I am new to unity \$\endgroup\$ – Wrong Turn Dec 6 '18 at 11:33

Screen.height returns the amount of pixels on the screen that are available to your app. In older versions of android the navigation bar would always remain static on the screen, eating a portion of it. This means that any app that runs does not have access on that portion of the screen. That is not an error, it's how the Android OS works, and in my opinion, it's the correct thing to do.

In newer versions, the navigation bar can get minimised if your app is set to run as fullscreen, which gives you access to the whole screen.

You also mention this causes a gap on the bottom of your screen. It's unclear why, unfortunately I can't give a solution to that unless you want to share some screenshots of what you mean.

| improve this answer | |
  • \$\begingroup\$ I think due to notch in device my game layout not show proper. So my problem is i cant find notch area of in android device. is there any way to find notch area in android device in unity? \$\endgroup\$ – Wrong Turn Dec 6 '18 at 11:52
  • \$\begingroup\$ @WrongTurn why do you need to find the notch area? The OS gives your game a specific space (Screen.width x Screen.height), you can only draw on that space. Android does not let developers mess with the notch so that it's not abused. \$\endgroup\$ – TomTsagk Dec 6 '18 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.