Skip to main content
Known Participant
May 25, 2013 9:05 PM UTC
Question

Detect if an Android device is a phone or a tablet

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 is closed to new replies. Start a new post to keep the conversation going.

5 replies

Lars Laborious
Legend
May 27, 2013 8:46 AM UTC

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.

Translate
Colin Holgate
Inspiring
May 27, 2013 11:45 AM UTC

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.

Translate
Lars Laborious
Legend
May 27, 2013 12:17 PM UTC

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

Translate
Colin Holgate
Inspiring
May 25, 2013 9:11 PM UTC

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.

Translate
eazyigz
Participating Frequently
Feb 13, 2017 3:51 PM UTC

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

Translate