Detect smartphone or tablet

Dear all,

I am trying to make my UI look good on both smartphones and tablets, but now I am facing this problem: how can I detect if I’m running on a smartphone or tablet?

My guess is to use **system.getInfo() **with a map name/type (e.g., “iPhone” with “Smartphone”, “iPad” with “Tablet”), but the  model property seems to be not suitable for this.

For instance, what is the _complete list of models_supported by corona? But more importantly, what if I’m running on a new device with an unknown model string?

How do you “safely” detect if you’re running on a smartphone or on a tablet?

Thanks for the pointers!

Best Design

Hi.  You’re thinking of this wrong.  Think in terms of resolutions.

  1. Choose a primary resolution (say iPad 3).  
  2. Next set up your config.lua appropriately.
  3. Then, add code to your app to accommodate screens that are wider or taller.

This is an art and a science.  Also, the decisions you make will not be the same as someone elses.  There is no perfect recipe, but rather you design based on the purpose and use of your game/app.

Some folks will suggest you use one of the advanced config.lua recipes.  I do not suggest this as it will just confuse you more if you’re new to this.  Instead, go with a fixed design resolution using letterbox and accommodate extra width/height by moving UI elements around.

Now that I’m writing this I think perhaps I should do some episodes on this for the Corona Geek Hangout… 

List Of Devices

There is no list of compatible devices…

If a device runs Window, OSX, Android, iOS, or Windows Phone OS, Corona runs on it.

Tablet or Phone

There is no way to detect this 100% consistently.  Phones and Tablets don’t give an identifier (that I know of) that says, “I’m a phone”, or “I’m a Tablet”.

For a rough estimate on whether it’s a phone or table on Android you could try using 

system.getInfo( "androidDisplayWidthInInches" ) system.getInfo( "androidDisplayHeightInInches" )

Some phones are huge though, and so you’ll need to decide yourself what size constitutes a tablet (I’d guess around 7 inches).

On iOS things are a bit easier, since there are only a handful of models. Try using 

system.getInfo("model")

That should return “iPad” when you are on an iPad and “iPhone” when on an iPhone.

Thanks to both of you!

Best Design

Hi.  You’re thinking of this wrong.  Think in terms of resolutions.

  1. Choose a primary resolution (say iPad 3).  
  2. Next set up your config.lua appropriately.
  3. Then, add code to your app to accommodate screens that are wider or taller.

This is an art and a science.  Also, the decisions you make will not be the same as someone elses.  There is no perfect recipe, but rather you design based on the purpose and use of your game/app.

Some folks will suggest you use one of the advanced config.lua recipes.  I do not suggest this as it will just confuse you more if you’re new to this.  Instead, go with a fixed design resolution using letterbox and accommodate extra width/height by moving UI elements around.

Now that I’m writing this I think perhaps I should do some episodes on this for the Corona Geek Hangout… 

List Of Devices

There is no list of compatible devices…

If a device runs Window, OSX, Android, iOS, or Windows Phone OS, Corona runs on it.

Tablet or Phone

There is no way to detect this 100% consistently.  Phones and Tablets don’t give an identifier (that I know of) that says, “I’m a phone”, or “I’m a Tablet”.

For a rough estimate on whether it’s a phone or table on Android you could try using 

system.getInfo( "androidDisplayWidthInInches" ) system.getInfo( "androidDisplayHeightInInches" )

Some phones are huge though, and so you’ll need to decide yourself what size constitutes a tablet (I’d guess around 7 inches).

On iOS things are a bit easier, since there are only a handful of models. Try using 

system.getInfo("model")

That should return “iPad” when you are on an iPad and “iPhone” when on an iPhone.

Thanks to both of you!