0

This code:

activity.getWindowManager().getDefaultDisplay().getMetrics(dm);

is reporting landscape xdpi = 195.38461 on the new Nexus 7. My tape measure says the screen is 1/16" shy of 6" wide, and at 1280 pixels, that works out to 215.57894.

And yes, our Android.xml says:

<uses-sdk android:minSdkVersion="16"/>

Is this just a bug, or are we doing something wrong?

Joshua Smith
  • 3,689
  • 4
  • 32
  • 45

1 Answers1

3

From this response from Dianne Hackborn:

Sorry you just can't use them. Nothing in the platform makes use of them. They need to be set by the manufacturer (there is no way for the platform to know what they are), and as of today they are just not consistently set correctly across devices, and because nothing in the platform relies on them it is easy for devices to have them set incorrectly.

Basically, you can't rely on what that returns, at all.

Kevin Coppock
  • 133,643
  • 45
  • 263
  • 274
  • So is there any way to find the actual size of pixels? – Joshua Smith Aug 24 '12 at 20:09
  • 2
    (And, how ironic, by the way since the manufacturer in this case is Google, who you'd think would want to comply with their own API standards, right?) – Joshua Smith Aug 24 '12 at 20:10
  • As far as I know, other than maintaining a database of devices (and that just seems fraught with peril), your best bet would be to have some sort of calibration, or input from the user on what their screen size is. If they input their screen size, you can use some basic math along with the resolution and aspect ratio to figure it out. It's not ideal, certainly, but it's the only option I can think of. – Kevin Coppock Aug 24 '12 at 20:13
  • OK, I'll credit you with answering my question, but I don't like the answer! :) – Joshua Smith Aug 24 '12 at 20:34
  • Haha, I don't like it either. :) One thing you could do, though, is at least keep a database of the most popular devices, and only request the screen size from the user if the device is unrecognized. It'd only be a one-time request, so it wouldn't be too intrusive. – Kevin Coppock Aug 24 '12 at 20:39