SPH-L710 (Sprint Galaxy S III) running 4.4.2 misreports xdpi and ydpi

265 views Asked by At

We've noticed a data anomaly recently in that a number of devices are misreporting their xdpi and ydpi via DisplayMetrics.

As a specific example, all SPH-L710 Sprint Galaxy S III devices running 4.4.2 are reporting an xdpi and ydpi of ~160. With a resolution of 1280x720, this would measure out to a ~9 inch screen size which is obviously not the case. Prior to 4.4.2, this device model was properly reporting its xdpi and ydpi: ~304 and ~306, respectively.

We're accessing this information through DisplayMetrics like so:

DisplayMetrics dm = getResources().getDisplayMetrics();
xdpi = dm.xdpi;
ydpi = dm.ydpi;

Has anyone else noticed these metrics to be inconsistent/unreliable? Is there a more accurate way to access this information?

Edit: I found this post regarding xdpi/ydpi inaccuracies. Both Romain and Dianne seem to acknowledge the issue - so the fact that the DisplayMetrics docs don't make note of these unreliable properties seems quite irresponsible to me.

1

There are 1 answers

1
Dalija Prasnikar On BEST ANSWER

From API 17 you can call getRealMetrics to get more accurate results.

DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getRealMetrics(dm);

xdpi = dm.xdpi;
ydpi = dm.ydpi;

From Display documentation

public void getRealMetrics (DisplayMetrics outMetrics)

Added in API level 17 Gets display metrics based on the real size of this display.

The size is adjusted based on the current rotation of the display.

The real size may be smaller than the physical size of the screen when the window manager is emulating a smaller display (using adb shell am display-size).

Parameters outMetrics A DisplayMetrics object to receive the metrics.