Is there an easy way to determine if a user is running an Android Tablet vs an Android Phone? I was thinking of using device aspect ratio to determine it.
Basically, I am trying to make my application run landscape-only on phones while on tablets allow them free range of orientation, so portrait and landscape.
not entirely sure how to check device diagonals, I know i *shouldn’t* use pixel length and width because smartphones can have a higher resolution then some tablets
First, a word of warning. Properties “androidDisplayWidthInInches” and “androidDisplayHeightInInches” have been known to return the wrong values on some devices. We believe this to be a firmware bug where sometimes manufacturers have simply set these values wrong or forgot to set them. It’s an issue that effects all native Android developers, making it impossible to tell what the physical screen sizes in inches reliably for all devices.
So, I recommend that you use the “androidDisplayApproximateDpi” property instead. This returns a hard coded DPI value for devices designated as ldpi, mpdi, hdpi, xhdpi, etc. It’s the only reliable means of fetching the DPI from all Android devices, with the only shortcoming is that it’s not accurate. It is merely a rough estimate. But this is as good as it gets on Android.
You can then calculate the approximate dimensions of the screen in inches as follows…
local approximateDpi = system.getInfo("androidDisplayApproximateDpi") local widthInInches = display.pixelWidth / approximateDpi local heightInInches = display.pixelHeight / approximateDpi
Nope. The width and height that you set in the “config.lua” file affects display.contentWidth and display.contentHeight. The pixel width and height properties will remain the same.
not entirely sure how to check device diagonals, I know i *shouldn’t* use pixel length and width because smartphones can have a higher resolution then some tablets
First, a word of warning. Properties “androidDisplayWidthInInches” and “androidDisplayHeightInInches” have been known to return the wrong values on some devices. We believe this to be a firmware bug where sometimes manufacturers have simply set these values wrong or forgot to set them. It’s an issue that effects all native Android developers, making it impossible to tell what the physical screen sizes in inches reliably for all devices.
So, I recommend that you use the “androidDisplayApproximateDpi” property instead. This returns a hard coded DPI value for devices designated as ldpi, mpdi, hdpi, xhdpi, etc. It’s the only reliable means of fetching the DPI from all Android devices, with the only shortcoming is that it’s not accurate. It is merely a rough estimate. But this is as good as it gets on Android.
You can then calculate the approximate dimensions of the screen in inches as follows…
local approximateDpi = system.getInfo("androidDisplayApproximateDpi") local widthInInches = display.pixelWidth / approximateDpi local heightInInches = display.pixelHeight / approximateDpi
Nope. The width and height that you set in the “config.lua” file affects display.contentWidth and display.contentHeight. The pixel width and height properties will remain the same.
You won’t get those values returned on iOS. However, you can use other “tricks” to help determine if you’re using an iPad vs. an iPhone. See this tutorial for details:
You won’t get those values returned on iOS. However, you can use other “tricks” to help determine if you’re using an iPad vs. an iPhone. See this tutorial for details: