Skip to main content
Known Participant
May 25, 2013
Question

Detect if an Android device is a phone or a tablet

  • May 25, 2013
  • 2 replies
  • 2469 views

Hi guys, I'm developing an Android app, but I've got some problem with the layout...

I absolutely need to know a way to detect if the device where my project's running on, is a tablet or a phone.

Can you help me?

Thanks

This topic has been closed for replies.

2 replies

Lars Laborious
Legend
May 27, 2013

This works fine for me:

function isPhone(mc:MovieClip):Boolean{

                    var tabletMinimumInches:Number = 5;

                    return(Math.max( mc.stage.fullScreenWidth , mc.stage.fullScreenHeight ) / Capabilities.screenDPI < tabletMinimumInches);

}

Then I just call it with isPhone(this); from my main document class (that extends MovieClip). If iit returns true, it's a phone.

Colin Holgate
Inspiring
May 27, 2013

Would that way only work correctly if you are using no_scale? If you use screenResolutionX you get the actual pixel size of the device.

Lars Laborious
Legend
May 27, 2013

Yes, you're right. Easy to forget that people approach this differently

Colin Holgate
Inspiring
May 25, 2013

Look at the capabilities class:

http://help.adobe.com/en_US/air/reference/html/flash/system/Capabilities.html

From screenResolutionX and screenResolutionY you know the resolution of the device, and from screenDPI you know the dots per inch. Those two sets of values will tell you the size of the screen in inches.

eazyigz
Participating Frequently
February 13, 2017

screenResolutionY under-reports the value on Android.  When it's supposed to by 1920, it reports it as 1794.