MonoDroid: How to determine if you are on a phone or tablet

In a recent Android based mobile application using Mono, our customer requirements dictated two sets of screen layouts: one for Android phones and one for Android tablets.

Easy right?

Well… No.  The requirement statement “detect if the device is a tablet or phone using MonoDroid and display the appropriate layout” turned out to not be as trivial as we originally suspected.

A quick Google search turned up several solutions using screen size and density to determine the answer to the phone vs. tablet question.  While workable, these solutions were far from fool proof due to the vast array of sizes and densities available on various Android devices.

Ugh.

During an offsite Red Solo cup session, the answer occurred to one of our senior developers:  Ask about IMEI!  If the device has an IMEI, its gotta be a phone (or a tablet with suspiciously phone like qualities).

Our Solution
A property exposed on a helper class which probes the IMEI and determines phone vs. tablet.

EDIT 02/27/2012: Code updated to reflect API support for 4G phones

public bool IsPhone
{
  get
  {
    return ((this.GetSystemService(Context.TelephonyService) as
                TelephonyManager).PhoneType != PhoneType.None);

   }
}

 

Quick, simple, solved!

Leave a Reply

Your email address will not be published. Required fields are marked *