Find Notch Cutout Type on Android

2k Views Asked by At

How can I get the notch cutout type of a device ? EDIT: As my question is not clear to everybody (I though it was): I am looking for a flag or an enum of some sort that contains the cutout type of the device. It could look like: "CutoutType_Corner". I am not sure if such an enum exists, I am pretty sure it does.

You can get the safe edge insets for all the sides to make sure that the notch (if there) is not covering any parts of the UI. (This is only important if you enable the app to also fill the given space to the left and right of the notch by e.g. setting the window flag LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES.)

In the android developer options you can simulate a display-cutout by choosing between:

  • (None)
  • Corner display cutout
  • (Double display cutout)
  • Tall display cutout

These options are just to simulate but they also provide the same information as if the device really had the chosen cutout as far as I can tell, so there should also be a way to find the set type.

Most of the UI in my case (but also in general in many cases) is centered horizontally without really touching the corners of the screen.

I would like to differentiate between the "corner"- and the "tall"-cutout as the corner is not really occupying important parts of the screen in my case. -> If the screen is a corner-cutout, I can neglect the safe edge insets.

As a visual example: The upper screen is from the Samsung Galaxy S10 with a corner cutout, the lower one is the Google Pixel 3 with a tall-cutout:

Cutout types visually.

The "-Example-" is fitting on the corner-cutout screen, while it is covered by the tall cutout.

Thanks!

1

There are 1 best solutions below

1
On

When I tried to solve this task the only suitable API I could find is DisplayCutout:

val corners = view.rootWindowInsets?.displayCutout?.boundingRects

boundingRects returns cutout rect for each corner and with heuristics you can understand what type of cutouts do you have.