Android added notch support on API 28, but how to handle it on devices running API 27 (Honor 10, Huawei P20, etc.) ?

I was trying to use DisplayCutoutCompat but I was not able to create an instance of it since documentation does not really point out how create one.

How to create the constructor parameter values: Rect safeInsets, List<Rect> boundingRects?

I also looked into the source code of the constructor, which is a bit confusing to me:

public DisplayCutoutCompat(Rect safeInsets, List<Rect> boundingRects) {
        this(SDK_INT >= 28 ? new DisplayCutout(safeInsets, boundingRects) : null);
    }

This will always return null on devices running API < 28. Thank you in advance.

  • There is no OS support for display notches prior to Android 9.0. You would need to contact the device manufacturers and ask them for advice regarding their notched displays running older versions of Android. – CommonsWare Aug 8 at 10:27

Google provided notch related APIs in Android P. Devices with notch and API version lower than P implemented their own notch APIs.You can consult the APIs from device specified documentation.

Also I did not see creation of DisplayCutoutCompat instance in official documentation, but you can create DisplayCutout as follow:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            DisplayCutout displayCutout = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout();
}

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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