Search code examples
androidiosappcelerator

function to know if is Tablet, iPad, Smartphone?


Is there a way to know if the app is running in: Android Tablet, iPad, or Smarthphone (handheld) ?

I am using classic development with Titanium Appcelerator SDK 5.3.0GA.

Thanks


Solution

  • My TitanUp library has a function that can tell you if you're running on a tablet. It checks explicitly for ipad, and then if it's running on android, it considers anything with a screen of 6.25 inches or greater to be a tablet.

    Here's how you use it:

    var TU = require ('/TitanUp/TitanUp'); TU.Device.getIsTablet();

    If you don't want to use the whole library, you could just look at the code in Device.js that sets the _screensize variable. Trace through those functions, and you can get the logical density factor which lets you calculate the physical width / height, from which you can get the diagonal screen size in inches.