0

Is there any way to get physical height and width of screen grammatically.

I tried this one

        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        double x = Math.pow(dm.widthPixels/dm.xdpi, 2);
        double y = Math.pow(dm.heightPixels/dm.ydpi, 2);
        double screenInches = Math.sqrt(x+y);

What else I found is, in Portrait and Landscape it returning different values.

and it's giving height probably, on my nexus it's 4.41 something. Any one have idea/suggestion here?

CoDe
  • 11,056
  • 14
  • 90
  • 197

1 Answers1

0

try this one :

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getRealSize(size);
int width = size.x;
int height = size.y;

DisplayMetrics dm = new DisplayMetrics();
display.getMetrics(dm);
double x = Math.pow(width/dm.xdpi, 2);
double y = Math.pow(height/dm.ydpi, 2);
double screenInches = Math.sqrt(x+y);
Muhammed Refaat
  • 8,914
  • 14
  • 83
  • 118