I'm making my app multi-screen (flex mobile). Basicly I want to know when I'm dealing with a tablet or a smartphone. Therefore I want to know the screen size in inch. I'm testing this out on a Desire HD (4.3 inch). My issue is: when I use the Capabilities.screenDPI, the emulator shows the correct value (217), however when I run this on my device, it gives me a wrong DPI value (240), the width and height are correct. Based on that dpi I get a wrong screen size in inch (3.887" != 4.3"). Again on the emulator everything runs fine. The device emulator is configured with the correct values, only when I run it on the real device (no emulator), I get a wrong DPI value.
I'm calculating it with the following piece of code:
var screenX:Number = stage.stageWidth;
var screenY:Number = stage.stageHeight;
var pixels:Number = (screenX*screenX) + (screenY*screenY);
var screenSize:Number = Math.sqrt(pixels)/Capabilities.screenDPI;
return (screenSize >= 6) ? "tablet" : "phone"
To spare you some time I'll give out the values of the Desire HD:
480 x 800 pixels, 4.3 inches (~217 ppi pixel density)
The formula used is simple ~ Pythagoras: a2 + b2 = c2 -> sqrt(c)/dpi = screen size in inch.
Based on Adobe, the DPI or PPI value can be used "interchangeably". (Adobe, Help). I haven't found any information wherether the dpi value is different than the ppi value, or wherether there is any possibility to use a ppi property in flex.
So on my real device I get:
480 x 800 pixels, 3.89" (~240 dpi).
Another note: I've seen that there are 3 default constants in flex mobile. Might it be that its directly thrown into one of these ? (I don't suspect so since I'm calling the Capabilities.screenDPI directly).
DPIClassification.DPI_160
DPIClassification.DPI_240
DPIClassification.DPI_320
What I mean is: How can I determine if it's a tablet or phone (in order to switch to another layout)? You can't follow the applicationDPI
road, since it's all mixed up with new devices like the Samsung Galaxy S3 (1280x720, 319 PPI) or the Apple iPad 3 (2048×1536, 264 PPI).
The Flex applicationDPI property will return either 160 (for most tablets), 240 (for most smartphones), and 320 for the iPhone 4/4S.
This is something that occurs under the hood to make life "Easier" for developers. Anything built for the specific DPI of the device may not be very expandable to other devices/platforms. I thought that the applicationDPI into one of those 3 values was a Flex thing, but it's entirely possible Flex just inherits it from AIR.
At the end of the day, I don't think there is any way you can use the DPI value to determine whether your app is running on a tablet or phone. Because the values I specify above are not universal. It's all a bit of a guessing game.
I'm surprised this works at all in the emulator, where I would expect the values returned to be the ones from your computer monitor, not equivalent to what the smartphone should be.