'Android: Display.getRealSize() vs WindowMetrics.getBounds()

on Samsung Galaxy A52 (SM-A525F, Android 12), the screen has 2400x1080 physical pixels.

When I call

Method getRealSize = Display.class.getMethod("getRealSize", Point.class);
Point realSize = new Point();
getRealSize.invoke(d, realSize);
//realSize = [1800, 810] //instead of [2400,1080]

WindowMetrics wMetrics = w.getCurrentWindowMetrics();
Rect r = wMetrics.getBounds();
//r = Rect(0, 0 - 1080, 2400) //correct

This code:

WindowManager w = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
Display d = w.getDefaultDisplay();
log(d.toString());

prints:

DisplayInfo{"Built-in Screen", real 1800 x 810, largest app 2186 x 2186, smallest app 1080 x 1017, modes [{id=1, width=1080, height=2400}]}, DisplayMetrics{density=1.96875, width=1640, height=810, scaledDensity=1.96875, xdpi=307.0, ydpi=305.0}

I'm wondering why getRealSize() and getBounds() produce different results.



Sources

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

Source: Stack Overflow

Solution Source