I don’t see a way to query either the pixels per inch or the physical dimensions of the screen. The graphic elements of my app scale up nicely from phones to tablets, but on a large tablet the text is so big it makes the app look as if it were designed for kindergarteners. I know I can query the logical dimensions of the screen in pixels, but I can’t infer screen size from that because there are some devices that pack a lot of pixels onto a small screen. I would like to know how big the physical screen is so I can adjust the font to an appropriate size. Is that possible?
Hi @sajent,
Which OS(es) are you targeting? iOS, Android-based, or both?
On Android, you can actually gather the screen info using various “system.getInfo()” calls:
http://docs.coronalabs.com/api/library/system/getInfo.html#androiddisplayxdpi
On iOS, this isn’t possible, but you could potentially detect iOS devices individually, since there’s a fairly small sub-set of iOS devices and screen densities, with several sharing common traits.
Out of curiosity, have you tried using the new “adaptive” content scale mode? This feature was added to daily builds several week ago, and now is available to all users in the most recent public build (#2511). See here for details:
http://docs.coronalabs.com/guide/basics/configSettings/index.html#scale
Hope this helps,
Brent
I acquire size by the following logic.
This is writing the easy logic which is not a program.
if (system.getInfo(“environment”) == “simulator” then
— default size
if system.getInfo( “architectureInfo” ) == “iPhone****” then
— The size of iPhone is set up according to the architecture.
If system.getInfo(“model”) ~= “iPhone” or “iPod” or “iPad” then
— The size of Android is acquired by getinfo.
h = system.getInfo( “androidDisplayHeightInInches” )
w = system.getInfo( “androidDisplayWidthInInches” )
end if
The size of this Android is not exact.
It seems that gap comes out depending on a model.
It seems that those who are looking are.
An easy screen size acquisition program is written.
However, there may be a bug (^o^;;;
– Terrible simple screen size acquisition.
– iOS and Android only
–
local isSimulator = (system.getInfo(“environment”) == “simulator”)
local iOS = {iPhone = true, iPod = true, iPad = true}
local model = system.getInfo(“model”)
local isIos = iOS[model] and true or false
local isAndroid = not isIos
local architecture = system.getInfo( “architectureInfo” )
local dpi = 163
local iPhonePpi = {{163,163},{163},{326,326,326},{326},{326,326,326,326},{326,326},{401,326}}
local iPodPpi = {{163},{163},{163},{326},{326}}
local iPadPpi = {{132},{132,132,132,132,163,163,163},{264,264,264,264,264,264},{264,264,264,326,326,326,326,326,326},{132,132,264,264}}
local m, n
local DisplayWidthInInches, DisplayHeightInInches
if isSimulator then
dpi = 72
DisplayWidthInInches, DisplayHeightInInches = display.pixelWidth / dpi, display.pixelHeight / dpi
elseif isIos then
m, n = string.match( architecture, “iPhone(%d+),(%d+)” )
if m ~= nil and n ~= nil then m,n=tonumber(m),tonumber(n) dpi=iPhonePpi[m][n] else
m, n = string.match( architecture, “iPod(%d+),(%d+)” )
if m ~= nil and n ~= nil then m,n=tonumber(m),tonumber(n) dpi=iPodPpi[m][n] else
m, n = string.match( architecture, “iPad(%d+),(%d+)” )
if m ~= nil and n ~= nil then m,n=tonumber(m),tonumber(n) dpi=iPodPpi[m][n] else
dpi = 326 – Error or New iPad?
end
end
end
DisplayWidthInInches, DisplayHeightInInches = display.pixelWidth / dpi, display.pixelHeight / dpi
else
DisplayWidthInInches, DisplayHeightInInches = system.getInfo(“androidDisplayWidthInInches”), system.getInfo(“androidDisplayHeightInInches”)
end
print("Display Size : ", DisplayWidthInInches, DisplayHeightInInches)
Thanks for all the responses. I don’t know how I missed “androidDisplayWidth/HeightInInches”, but I have it working now to adjust text size on various Android devices. As for the iOS technique suggested by CyberCatfish, wouldn’t it be great if system.getInfo() had an option “iOSDisplayWidth/HeightInInches” that encapsulated that logic? Maybe even merge the platforms into one API call? That way hundreds of developers wouldn’t have to rewrite a piece of their apps whenever Apple announces a new phone or tablet. Can I consider that feature request submitted now, or is there another more appropriate channel?
Hi @sajent,
Which OS(es) are you targeting? iOS, Android-based, or both?
On Android, you can actually gather the screen info using various “system.getInfo()” calls:
http://docs.coronalabs.com/api/library/system/getInfo.html#androiddisplayxdpi
On iOS, this isn’t possible, but you could potentially detect iOS devices individually, since there’s a fairly small sub-set of iOS devices and screen densities, with several sharing common traits.
Out of curiosity, have you tried using the new “adaptive” content scale mode? This feature was added to daily builds several week ago, and now is available to all users in the most recent public build (#2511). See here for details:
http://docs.coronalabs.com/guide/basics/configSettings/index.html#scale
Hope this helps,
Brent
I acquire size by the following logic.
This is writing the easy logic which is not a program.
if (system.getInfo(“environment”) == “simulator” then
— default size
if system.getInfo( “architectureInfo” ) == “iPhone****” then
— The size of iPhone is set up according to the architecture.
If system.getInfo(“model”) ~= “iPhone” or “iPod” or “iPad” then
— The size of Android is acquired by getinfo.
h = system.getInfo( “androidDisplayHeightInInches” )
w = system.getInfo( “androidDisplayWidthInInches” )
end if
The size of this Android is not exact.
It seems that gap comes out depending on a model.
It seems that those who are looking are.
An easy screen size acquisition program is written.
However, there may be a bug (^o^;;;
– Terrible simple screen size acquisition.
– iOS and Android only
–
local isSimulator = (system.getInfo(“environment”) == “simulator”)
local iOS = {iPhone = true, iPod = true, iPad = true}
local model = system.getInfo(“model”)
local isIos = iOS[model] and true or false
local isAndroid = not isIos
local architecture = system.getInfo( “architectureInfo” )
local dpi = 163
local iPhonePpi = {{163,163},{163},{326,326,326},{326},{326,326,326,326},{326,326},{401,326}}
local iPodPpi = {{163},{163},{163},{326},{326}}
local iPadPpi = {{132},{132,132,132,132,163,163,163},{264,264,264,264,264,264},{264,264,264,326,326,326,326,326,326},{132,132,264,264}}
local m, n
local DisplayWidthInInches, DisplayHeightInInches
if isSimulator then
dpi = 72
DisplayWidthInInches, DisplayHeightInInches = display.pixelWidth / dpi, display.pixelHeight / dpi
elseif isIos then
m, n = string.match( architecture, “iPhone(%d+),(%d+)” )
if m ~= nil and n ~= nil then m,n=tonumber(m),tonumber(n) dpi=iPhonePpi[m][n] else
m, n = string.match( architecture, “iPod(%d+),(%d+)” )
if m ~= nil and n ~= nil then m,n=tonumber(m),tonumber(n) dpi=iPodPpi[m][n] else
m, n = string.match( architecture, “iPad(%d+),(%d+)” )
if m ~= nil and n ~= nil then m,n=tonumber(m),tonumber(n) dpi=iPodPpi[m][n] else
dpi = 326 – Error or New iPad?
end
end
end
DisplayWidthInInches, DisplayHeightInInches = display.pixelWidth / dpi, display.pixelHeight / dpi
else
DisplayWidthInInches, DisplayHeightInInches = system.getInfo(“androidDisplayWidthInInches”), system.getInfo(“androidDisplayHeightInInches”)
end
print("Display Size : ", DisplayWidthInInches, DisplayHeightInInches)
Thanks for all the responses. I don’t know how I missed “androidDisplayWidth/HeightInInches”, but I have it working now to adjust text size on various Android devices. As for the iOS technique suggested by CyberCatfish, wouldn’t it be great if system.getInfo() had an option “iOSDisplayWidth/HeightInInches” that encapsulated that logic? Maybe even merge the platforms into one API call? That way hundreds of developers wouldn’t have to rewrite a piece of their apps whenever Apple announces a new phone or tablet. Can I consider that feature request submitted now, or is there another more appropriate channel?