How can I get the actual screen size when the application is in compatibility mode

I am trying to read the screen size using DeviceMetrics, but it gives me a scaled size, not the actual screen size.

How can I read the actual screen size in compatibility mode?

For example, the application runs on a 480x800 screen.
But it gives me 400x700, due to compatibility mode.

+4
source share
1 answer

try this code:

if (Build.VERSION.SDK_INT >= 11) { Point point= new Point(); getWindowManager().getDefaultDisplay().getRealSize(point); screenWidth = point.x; screenHeight = point.y; } else { DisplayMetrics displayMetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); screenWidth = displayMetrics.widthPixels; screenHeight = displayMetrics.heightPixels; } 

note: because of the getRealSize method getRealSize you might need to catch NoSuchMethodError Exception

0
source

All Articles