I am working on supporting multiple screen sizes in my Android app and I need to know the physical screen size of the device.
On a Sony Ericsson X10, I'm querying the physical screen resolution and density and trying to calculate the screen size (resolution/density = size) but the result is about 1.5 times the actual size!
Here's the code:
DisplayMetrics metrics = c.getResources().getDisplayMetrics();
mPhysicalScreenWidth = metrics.widthPixels / metrics.xdpi;
mPhysicalScreenHeight = metrics.heightPixels / metrics.ydpi;
Log.d(TAG, "DisplayMetrics: widthPixels=" + metrics.widthPixels + " xdpi=" + metrics.xdpi +
" heightPixels=" + metrics.heightPixels + " ydpi=" + metrics.ydpi);
Log.d(TAG, "Physical screen width=" + mPhysicalScreenWidth + "\", height=" + mPhysicalScreenHeight + "\"");
The output in the log:
DisplayMetrics: widthPixels=480 xdpi=160.41878 heightPixels=854 ydpi=159.49677
Physical screen width=2.9921684", height=5.3543406"
This actual size is only 2" (wide) x 3.5" (high)!?
Am I doing something wrong?
I am using the Android 1.6 SDK and I've set all the <supports-screens> attributes in the manifest to true.