toto_tata
toto_tata

Reputation: 15392

Android DisplayMetrics returns incorrect screen size in pixels

I have a Samsung Galaxy S20+.

I run this code:

DisplayMetrics displayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    mScreenHeight = displayMetrics.heightPixels;
    mScreenWidth = displayMetrics.widthPixels;

I get:

mScreenHeight = 2201.0 mScreenWidth = 1080.0

Whereas the S20+ screen resolution is 1440x3200 according to this page.

Such a big gap is not just a question of status bar height.

How can I get the real screen size in pixels ?

Thanks !

Upvotes: 1

Views: 1005

Answers (1)

Gauthier
Gauthier

Reputation: 4978

Recent Galaxy S devices have a setting to change the screen resolution. On the S20+ there are 3 options:

  • WQHD+: 3200x1440
  • FHD+: 2400x1080
  • HD+: 1600x720

You're likely in the FHD+ mode. Even though the device has a real pixel dimension of 3200x1440, your usable software window is downscaled and this is what the DisplayMetrics object is giving you.

Upvotes: 1

Related Questions