0

So I used this code to calculate screen size, but it returns wrong results. It returns a screen size of 4'33" but in reality the screen is 5'.0" So the value 4.33" corresponds to what? Current activity size?

DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics);


        float height=metrics.heightPixels/metrics.xdpi;
        float width=metrics.widthPixels/metrics.ydpi;

And then, the view

 "The screen size is:"+(float)Math.sqrt(height*height+width*width) +"\n" 
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

0

Use double instead of float and see the results. :)

Rezaul Karim
  • 830
  • 8
  • 15