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)?
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 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!
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);