- Home /
How can I check if it's a tablet? (both iOS and Android)
I used to check if Screen.height was greater than 1024, but this doesnt work anymore since recent iPhones have 1136 and higher (and Android phones too)
How can I now check that the device is a tablet (or NOT a mobile phone)?
You simply want to know whether the device is also capable of making/receiving phone calls? Why?
I want to know if the screen size is large. To adapt my game controls
Answer by NeverHopeless · Jul 31, 2015 at 01:55 PM
You may consume this function:
//calculate physical inches with pythagoras theorem
public static float DeviceDiagonalSizeInInches ()
{
float screenWidth = Screen.width / Screen.dpi;
float screenHeight = Screen.height / Screen.dpi;
float diagonalInches = Mathf.Sqrt (Mathf.Pow (screenWidth, 2) + Mathf.Pow (screenHeight, 2));
Debug.Log ("Getting device inches: " + diagonalInches);
return diagonalInches;
}
and use it like:
if(Application.platform == RuntimePlatform.Android && DeviceDiagonalSizeInInches() > 6.5f)
{
// Tablets
}
Hope it helps!
Answer by austinborden · Dec 27, 2019 at 03:22 PM
Through some beta testing on Android I've found there's at least one phone out there that gets reported as a tablet with this code, the OnePlus GM1913. Its screen is 1080x2340 at 380 dpi. To restrict this a bit more, I added an aspect ratio test. I'm not aware of any tablet that has an aspect ratio greater than 2:1. Using @NeverHopeless answer, add the aspect ratio check like this:
var aspectRatio = Mathf.Max(Screen.width, Screen.height) / Mathf.Min(Screen.width, Screen.height)
var isTablet = (DeviceDiagonalSizeInInches() > 6.5f && aspectRatio < 2f);
Answer by kemar · Jul 31, 2015 at 01:30 PM
Hi,
You can use this:
function Start () {
if (Application.platform == RuntimePlatform.Android)
print ("Android");
else if(Application.platform == RuntimePlatform.IPhonePlayer)
print("Iphone");
}
Hi thanks for the response. But I'm asking how to check if it's a tablet, not it's platform.
Your answer
Follow this Question
Related Questions
size of window 0 Answers
Screen Resolution -1 Answers
How to disable object scaling when screen height is changing 0 Answers
Screen.currentResolution values don't change after SetResolution in Mac builds 1 Answer
I have problems with the Camera.ortographic to adapt the view to screens with different resolutions. 2 Answers