Skip to main content
November 12, 2015
Question

How do I get the DPI and resolution of device?

  • November 12, 2015
  • 1 reply
  • 1347 views

How do I get the DPI and resolution of device?

Is this easily possible yet? I remember this wasn't really possible a few years ago.

This topic has been closed for replies.

1 reply

Known Participant
November 12, 2015

Could be you've been looking for this http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/Capabilities.html#screenDPI ?

This like is more general on how to develop multi res apps Multiscreen Support in Mobile AIR Applications

Also, Starling/Feathers have helpful util function to do that.

November 12, 2015

Thanks for this link:

Multiscreen Support in Mobile AIR Applications

I will try it out and see how it goes.

Projectitis
Inspiring
November 19, 2015

I use capabilities.screenDPI in every app, and have done for some while.  It seems to work ok!

Specifically, I use this snippet of code to detect if I'm running on a screen larger than 6", and then I use that to scale down my UI so that it doesn't look enormous on larger screens:

var screenWidth : Number = Math.max( stage.fullScreenWidth, stage.fullScreenHeight );

var screenHeight : Number = Math.min( stage.fullScreenWidth, stage.fullScreenHeight );

var w : Number = screenWidth / Capabilities.screenDPI;

var h : Number = screenHeight / Capabilities.screenDPI;

var screenSizeDiagonal : Number = Math.sqrt( w * w + h * h );

var isTablet : Boolean = screenSizeDiagonal >= TABLET_SCREEN_SIZE; // TABLET_SCREEN_SIZE = 6

Please note that this is just a snippet of the full code I use, and there is actually a whole bunch more that goes on to detect proper screen size and orientation.  This will work in most cases though.