Assuming you meant the device's screen sizes (you wrote "of a device", not 
the screen size) then the sizes are correct for most of the time.

When the app is running on a device that has no physical buttons or running 
on an ICS+ device while being targeted lower (thus causing the menu bar to 
show) the screen size is reported sans that bar.

As an example, a galaxy nexus while being 720x1280  (4.65 inches diagonal) 
is reported as 720x1184 (4.36 inches diagonal).

On Thursday, October 11, 2012 5:36:19 PM UTC+2, bob wrote:
>
> I'm trying to make a routine that gets the width and height of a device in 
> inches:
>
> Here's what I came up with:
>
> public void get_display_size() {
>
> DisplayMetrics metrics = new DisplayMetrics();
> getWindowManager().getDefaultDisplay().getMetrics(metrics);
> float width_in = metrics.widthPixels / metrics.xdpi;
> float height_in = metrics.heightPixels / metrics.ydpi;
>
> }
>
> Does this look good?
>
> Or is there a better way?
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to