6

There are some devices such as Huawei p20(running android 8,8.1) which has in-built notch on the top. The current way to get the size of the screen is

 Display display = getWindow().getWindowManager().getDefaultDisplay();
 Point screenSize = new Point();

 display.getRealSize(screenSize);
 //screenSize.x
//screenSize.y

And it's leading the game out of screen. So, is there any way to solve notch issue with android P and Pre-p devices.

rampr
  • 1,877
  • 4
  • 21
  • 36
Javasamurai
  • 666
  • 7
  • 21

2 Answers2

3

The status bar(where all your notifications are) always adjusts to the depth of the notch. Look at the pixel 3 which has the largest notch in the world :p The status bar becomes as tall as the notch.

enter image description here

So the notch is only a problem if your app is in a full screen(content draws underneath the status bar) and it may cover some of your content. Make your app non-full screen (only draw below the status bar) and you don't have to worry about any notch size in the future. A lot of games ignore the status bar from their content.

psydj1
  • 181
  • 10
2

There are only a few android devices with notch option and currently it is not possible to get the exact screen size of such devices using Android APIs.

BUT there is a work around, you can check the name of device and adjust your layout accordingly.

There is one popular Android library to get the market name of an Android device. Check more information here : https://github.com/jaredrummler/AndroidDeviceNames

How to use this lib:

String deviceName = DeviceName.getDeviceName();

Hope this will help you to focus on your development instead of wasting time!

Vikasdeep Singh
  • 20,983
  • 15
  • 78
  • 104
  • There are actually multiple devices with notch even on Android 8.0. – Javasamurai May 23 '18 at 08:24
  • @SyedZainulAbedin, yes but **currently** Android is not providing any API to check that so we need to use the above workaround only. – Vikasdeep Singh May 23 '18 at 08:39
  • @VicJordan I know it is late, but you can check https://stackoverflow.com/questions/52514075/how-to-detect-if-device-support-notch-display, but only works if you target sdk 28, which causes other issue https://developer.android.com/about/versions/pie/restrictions-non-sdk-interfaces. it broke some old code for me. – M.Baraka Nov 09 '18 at 21:18