If it's important to know the screen size fairly accurately, it might
be wise to have a "calibrate screen size" setup option in your app --
display a ruler on the screen and let the user do up/down buttons
until it matches a physical ruler, eg.  Otherwise you're always going
to be at the mercy of the manufacturer who may use the same code on
two different models with different screen sizes.

On Aug 4, 4:12 pm, sdphil <[email protected]> wrote:
> I am trying to determine the physical size of a screen in inches.
>
> Normally, I could do something like this:
>
>     DisplayMetrics metrics = new DisplayMetrics();
>     getWindowManager().getDefaultDisplay().getMetrics( metrics );
>
> Then use metrics.widthPixels and metrics.heightPixels.  Now that I
> know the width and height in pixels, I should be able to calculate
> size in inches if I know the density.  Easy enough, metrics.xdpi and
> metrics.ydpi.
>
> Then screen dimension in inches should be:
>
>     widthInInches = metrics.widthPixels / metrics.xdpi;
>     heightInInches = metrics.heightPixels / metrics.ydpi;
>
> Seems simple enough except that it doesn't work.
>
> On a Motorola Droid, the system reports back: xdpi and ydpi as 96
> (which cannot be true).
>
> And the screen resolution as: 480 x 854.  Which results in a width of
> 5" x 8.9" -- which as I'm holding this in my hand right now, I must
> say - cannot be correct.
>
> Any ideas on how to accurately calculate this?

-- 
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