So, we have lots of interesting ways to determine screen resolution and have Corona handle dynamic scaling, etc, but what if you want to provide a different interface for iPad and Android tablets than on iPhone and other phones? For example, you want to have a margin or border to your game on iPad but be edge to edge on phones? How do we determine when to do this with a universal binary?
I’m sure you’re aware of these checks, but I use these and others to set up my environment and to made positioning decisions:
-- Measurement and Spacing -- ============================================================= \_G.w = display.contentWidth \_G.h = display.contentHeight \_G.centerX = display.contentCenterX \_G.centerY = display.contentCenterY --\_G.scaleX = 1/display.contentScaleX --\_G.scaleY = 1/display.contentScaleY \_G.fullw = display.actualContentWidth \_G.fullh = display.actualContentHeight \_G.unusedWidth = \_G.fullw - \_G.w \_G.unusedHeight = \_G.fullh - \_G.h \_G.deviceWidth = math.floor((fullw/display.contentScaleX) + 0.5) \_G.deviceHeight = math.floor((fullh/display.contentScaleY) + 0.5) \_G.left = 0 - unusedWidth/2 \_G.top = 0 - unusedHeight/2 \_G.right = w + unusedWidth/2 \_G.bottom = h + unusedHeight/2 \_G.orientation = ( w \> h ) and "landscape" or "portrait" \_G.isLandscape = ( w \> h ) \_G.isPortrait = ( h \> w ) -- ============================================================= -- Environment -- ============================================================= \_G.onSimulator = system.getInfo( "environment" ) == "simulator" \_G.oniOS = ( system.getInfo("platformName") == "iPhone OS") \_G.onAndroid = ( system.getInfo("platformName") == "Android") \_G.onOSX = ( system.getInfo("platformName") == "Mac OS X") \_G.onWin = ( system.getInfo("platformName") == "Win") -- ============================================================= -- Device -- ============================================================= \_G.oniPad = ( string.find( system.getInfo("architectureInfo"), "iPad" ) ~= nil ) \_G.oniPhone4 = ( string.find( system.getInfo("architectureInfo"), "iPhone4" ) ~= nil ) \_G.oniPhone5 = ( string.find( system.getInfo("architectureInfo"), "iPhone5" ) ~= nil ) \_G.oniPhone5s = ( string.find( system.getInfo("architectureInfo"), "iPhone6" ) ~= nil ) \_G.oniPhone6 = ( string.find( system.getInfo("architectureInfo"), "iPhone7,2" ) ~= nil ) \_G.oniPhone6Plus = ( string.find( system.getInfo("architectureInfo"), "iPhone7,1" ) ~= nil ) \_G.onAndroidTablet = ( (system.getInfo( "androidDisplayWidthInInches" ) or 0) \> 5 or (system.getInfo( "androidDisplayHeightInInches" ) or 0) \> 5 ) \_G.onTablet = onAndroidTablet or oniPad -- =============================================================
The ‘onAndroidTablet’ bit is new in my configs. I’m still deciding on the ‘best’ test.
Oh, and as you know you can make these same checks in config.lua and build up any setup you need per device type and/or category.
Thanks for that - very useful setup.
I’ve not put any logic into my config.lua actually. I do intend to start as it is a very sensible place to have that detection code.
I’ve always just used the platform name to check device size as I’ve been focused on iOS so far. The thing is, with so many Android devices and potential Windows devices out there, how best to determine the physical size of the device? It’s akin to the iPhone 5s vs iPad 1 problem - wildly differing resolutions against the physical dimensions.
It would be great to have a system value which tells you the physical size in metric of the device itself, aside from the screen dimensions, I think.
The good news is, on Android you can get the physical width and height of the device screen. iOS…well that takes more work.
Of course, on iOS it’s easier because we know which devices we’re talking about. 
<horacebury>: I’ve found the below works, though I haven’t tested it on a large universe of Android tablets. (I use a templating system, in a non-game app, that supports different templates for different size tablets.)
local approximateDpi = system.getInfo("androidDisplayApproximateDpi") local width = display.pixelWidth / approximateDpi local height = display.pixelHeight / approximateDpi if width \> 4.5 and height \> 7 then deviceType = "large tablet" elseif width \> 3.25 and height \> 5.4 then deviceType = "small tablet" end
I think I may have used that approach vs. the one suggested by <roaminggamer> because of the lack of support for androidDisplayWidthInInches and androidDisplayHeightInInches on some tablets. But both may work equally well.
Nice! I like the DPI method there.
Yeah, I like that. Nice work.
What’s the best way to future proof this code for iPhones?
I’m thinking of a case where a new iPhone is released and you don’t have time to immediately push out an update. Or you may be waiting for Corona to fix some bugs with the new version of iOS before updating apps.
I would want the code to just treat any new iPhone like an iPhone 6 or 6+, until the app gets updated.
Thanks for the useful information everyone! I have a question related to the Android tablet detection while working in the simulator. Right now, I’m getting a nil value whenever I call androidDisplayApproximateDpi or the androidDisplayWidth(Height)InInches arguments with getInfo.
Is that expected behavior? If so, is there a method to develop on the simulator and still determine tablet/phone status for Android? I’m in a situation where my object layout would be determined by the physical size of the device. iOS is easy, but no go with Android so far.
I’m sure you’re aware of these checks, but I use these and others to set up my environment and to made positioning decisions:
-- Measurement and Spacing -- ============================================================= \_G.w = display.contentWidth \_G.h = display.contentHeight \_G.centerX = display.contentCenterX \_G.centerY = display.contentCenterY --\_G.scaleX = 1/display.contentScaleX --\_G.scaleY = 1/display.contentScaleY \_G.fullw = display.actualContentWidth \_G.fullh = display.actualContentHeight \_G.unusedWidth = \_G.fullw - \_G.w \_G.unusedHeight = \_G.fullh - \_G.h \_G.deviceWidth = math.floor((fullw/display.contentScaleX) + 0.5) \_G.deviceHeight = math.floor((fullh/display.contentScaleY) + 0.5) \_G.left = 0 - unusedWidth/2 \_G.top = 0 - unusedHeight/2 \_G.right = w + unusedWidth/2 \_G.bottom = h + unusedHeight/2 \_G.orientation = ( w \> h ) and "landscape" or "portrait" \_G.isLandscape = ( w \> h ) \_G.isPortrait = ( h \> w ) -- ============================================================= -- Environment -- ============================================================= \_G.onSimulator = system.getInfo( "environment" ) == "simulator" \_G.oniOS = ( system.getInfo("platformName") == "iPhone OS") \_G.onAndroid = ( system.getInfo("platformName") == "Android") \_G.onOSX = ( system.getInfo("platformName") == "Mac OS X") \_G.onWin = ( system.getInfo("platformName") == "Win") -- ============================================================= -- Device -- ============================================================= \_G.oniPad = ( string.find( system.getInfo("architectureInfo"), "iPad" ) ~= nil ) \_G.oniPhone4 = ( string.find( system.getInfo("architectureInfo"), "iPhone4" ) ~= nil ) \_G.oniPhone5 = ( string.find( system.getInfo("architectureInfo"), "iPhone5" ) ~= nil ) \_G.oniPhone5s = ( string.find( system.getInfo("architectureInfo"), "iPhone6" ) ~= nil ) \_G.oniPhone6 = ( string.find( system.getInfo("architectureInfo"), "iPhone7,2" ) ~= nil ) \_G.oniPhone6Plus = ( string.find( system.getInfo("architectureInfo"), "iPhone7,1" ) ~= nil ) \_G.onAndroidTablet = ( (system.getInfo( "androidDisplayWidthInInches" ) or 0) \> 5 or (system.getInfo( "androidDisplayHeightInInches" ) or 0) \> 5 ) \_G.onTablet = onAndroidTablet or oniPad -- =============================================================
The ‘onAndroidTablet’ bit is new in my configs. I’m still deciding on the ‘best’ test.
Oh, and as you know you can make these same checks in config.lua and build up any setup you need per device type and/or category.
Thanks for that - very useful setup.
I’ve not put any logic into my config.lua actually. I do intend to start as it is a very sensible place to have that detection code.
I’ve always just used the platform name to check device size as I’ve been focused on iOS so far. The thing is, with so many Android devices and potential Windows devices out there, how best to determine the physical size of the device? It’s akin to the iPhone 5s vs iPad 1 problem - wildly differing resolutions against the physical dimensions.
It would be great to have a system value which tells you the physical size in metric of the device itself, aside from the screen dimensions, I think.
The good news is, on Android you can get the physical width and height of the device screen. iOS…well that takes more work.
Of course, on iOS it’s easier because we know which devices we’re talking about. 
<horacebury>: I’ve found the below works, though I haven’t tested it on a large universe of Android tablets. (I use a templating system, in a non-game app, that supports different templates for different size tablets.)
local approximateDpi = system.getInfo("androidDisplayApproximateDpi") local width = display.pixelWidth / approximateDpi local height = display.pixelHeight / approximateDpi if width \> 4.5 and height \> 7 then deviceType = "large tablet" elseif width \> 3.25 and height \> 5.4 then deviceType = "small tablet" end
I think I may have used that approach vs. the one suggested by <roaminggamer> because of the lack of support for androidDisplayWidthInInches and androidDisplayHeightInInches on some tablets. But both may work equally well.
Nice! I like the DPI method there.
Yeah, I like that. Nice work.
What’s the best way to future proof this code for iPhones?
I’m thinking of a case where a new iPhone is released and you don’t have time to immediately push out an update. Or you may be waiting for Corona to fix some bugs with the new version of iOS before updating apps.
I would want the code to just treat any new iPhone like an iPhone 6 or 6+, until the app gets updated.