michalsrb
michalsrb

Reputation: 4891

Find if screen has rounded corners

I am looking for a way to determine whether Android device has screen with rounded corners and ideally also the radius.

My usecase is a game that consist of a single fullscreen OpenGL view. It renders some UI elements close to the edges and borders to give as much area as possible to the game itself. But when the screen has rounded corners, they would be partially hidden, so they need to be positioned differently.

Upvotes: 23

Views: 9013

Answers (2)

Vikasdeep Singh
Vikasdeep Singh

Reputation: 21766

Update as of 6th June 2019

Android officially supports display cutouts on devices running Android 9 (API level 28) and higher.

Reference: https://developer.android.com/guide/topics/display-cutout/

Currently (7th May 2018) you can only check if the physical screen is rounded or not (for Android Wear) using [isRounded()][1] method but can not check if screen corners are rounded.

I think there are only a few devices with rounded corners out there. So it's better to just 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 here for more information: https://github.com/jaredrummler/AndroidDeviceNames/

Usage:

String deviceName = DeviceName.getDeviceName();

Hope this workaround will help you temporarily.

Maybe all devices in the future will release with round corner screens (just an assumption).

Upvotes: 5

rockgecko
rockgecko

Reputation: 4207

Android S Developer Preview adds a RoundedCorner API, via WindowInsets.getRoundedCorner(int position). It provides the center point and radius of each rounded corner.

Ref: https://developer.android.com/about/versions/12/features#rounded_corner_apis

Upvotes: 7

Related Questions