'Getting screen width with newer phones

I'm using a Samsung Galaxy S20 phone and I'm trying to get the width of the display using:

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);

height2 = metrics.heightPixels;
width2 = metrics.widthPixels;

This returns 810, but seeing the phone specifications on the internet the actual screen width is 1080. I started having problems in code because of this, is there a way to get the actual screen width in Java?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source