How to detect if app is running on a phone or tablet?

I am writing an app in XNA Monogame. Is their a way for my app to determine if it is running on a phone versus a tablet?

Thanks in advance.

This might help.

EDIT

Extra into:

I think you may start from getting the current default display metrics to get the height and width and work from there, good luck ^_^Y

1 Like

That tells you nothing, some phones can have a much higher resolution than a tablet…

Im pretty sure even “Xamarin essential” Idiom device info are using the display metrics resources Hieght, WidthPixels, density and etc… and its defeault tabletCrossOver fix value to get the correct DeviceIdiom : )

or it will return DeviceIdiom.Unknown ^_^y

More or less, but even compilation symbols are hopeless as there is not a complete list anywhere… [is there?]

I think I haven’t seen a phone with Diagonal size of 7" this piece of code works on my end whatever your current device orientation.

protected override void Initialize()
{
      // TODO: Add your initialization logic here

      base.Initialize();

      if( DroidDiagonalScreenSize() >= 7 )
      {
          _IsTablet = true;
      }
      else
      {
          _IsTablet = false;
      }

}

bool _IsTablet = false;

/// <summary>
/// Get android device default orientation diagonal screen size 
/// </summary>
/// <returns>Return diagonal screen size in inches</returns>
public static double DroidDiagonalScreenSize()
{            
        DisplayMetrics m_DM = new DisplayMetrics(); Activity.WindowManager.DefaultDisplay.GetMetrics(m_DM);
        //
        double m_Height = m_DM.HeightPixels / (double)m_DM.DensityDpi;
               m_Height = System.Math.Pow(m_Height, 2);
        //
        double m_Width  = m_DM.WidthPixels  / (double)m_DM.DensityDpi;
               m_Width  = System.Math.Pow(m_Width, 2);
        //
        double m_DiagSize = System.Math.Sqrt( m_Height + m_Width );
        //
        return m_DiagSize;
    }
2 Likes

If that works, cool!

2 Likes

Thanks to you and MrValentine.

2 Likes