0

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?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
csant85
  • 21
  • 4
  • 1
    Bear in mind that screen width is useless in modern Android app development. Split-screen is available on most Android devices. Foldables and freeform multi-window (Chrome OS, Samsung DeX, etc.) also tend to split the screen, as does Android 12L on tablets. For most apps, focusing on the size of your window is far more relevant. – CommonsWare Feb 11 '22 at 18:46
  • Does this answer your question? [How to get screen dimensions as pixels in Android](https://stackoverflow.com/questions/1016896/how-to-get-screen-dimensions-as-pixels-in-android) – Alias Cartellano Feb 11 '22 at 19:34

0 Answers0