Reputation: 13
I am coding to find out the pieces of information of the display in android. Something I did to find out the screen height in pixels is:
public static int getScreenHeight() {
return Resources.getSystem().getDisplayMetrics().heightPixels;}
And it's working properly. But I also wanted to get the screen's physical width and height , how do I get this? is it possible? Thanks
Upvotes: 1
Views: 1189
Reputation: 54244
The DisplayMetrics
class includes all the information you need:
widthPixels
xdpi
And
heightPixels
ydpi
These second values correspond to the number of pixels per inch for the physical screen, so you can compute e.g. the width in inches like this:
float widthInches = metrics.widthPixels / metrics.xdpi;
Upvotes: 5