Skip to main content
Known Participant
May 17, 2013
Question

What is the best way to find out the underlying platform within AIR?

I'd like to know whether Air is running on iOS, Windows, Android or Blackberry.

This topic is closed to new replies. Start a new post to keep the conversation going.

1 reply

Douglas McCarroll
Inspiring
May 17, 2013

Here's our Utuls_System class. It's a work in progress, incomplete, and does other stuff as well, but take a look at init() and isIOS() etc...

package com.brightworks.util

{

    import com.langcollab.languagementor.constant.Constant_AppConfiguration;

    import flash.system.Capabilities;

    public class Utils_System

    {

        public static const OS_CATEGORY__ANDROID:String = "osCategory_Android";

        public static const OS_CATEGORY__IOS:String = "osCategory_iOS";

        public static const OS_CATEGORY__MAC:String = "osCategory_Mac";

        public static const OS_CATEGORY__UNKNOWN:String = "osCategory_Unknown";

        public static const OS_CATEGORY__WINDOWS_DESKTOP:String = "osCategory_WindowsDesktop";

        public static const OS_CATEGORY__WINDOWS_MOBILE:String = "osCategory_WindowsMobile";

        private static var _isInitialized:Boolean;

        private static var _isMobileDevice:Boolean;

        // ****************************************************

        //

        //          Getters / Setters

        //

        // ****************************************************

        private static var _appHeight:int;

        public static function get appHeight():int

        {

            init();

            return _appHeight;

        }

        private static var _appWidth:int;

        public static function get appWidth():int

        {

            init();

            return _appWidth;

        }

        private static var _dpi:int;

        public static function get dpi():int

        {

            init();

            return _dpi;

        }

        private static var _osCategory:String;

        public static function get osCategory():String

        {

            return _osCategory;

        }

        // ****************************************************

        //

        //          Public Methods

        //

        // ****************************************************

        public static function getAppStoreName():String

        {

            if (isIOS())

                return "Play Store";

            return "App Store";

        }

        public static function isIOS():Boolean

        {

            return (osCategory == OS_CATEGORY__IOS);

        }

        public static function isScreenResolutionHighEnough(requiredX:uint, requiredY:uint, isMobile:Boolean):Boolean

        {

            init();

            if ((isMobile) && (!Utils_System._isMobileDevice))

            {

                // We're testing on the desktop, and can't check screen size

                return true;

            }

            if (Capabilities.screenResolutionX < requiredX)

                return false;

            if (Capabilities.screenResolutionY < requiredY)

                return false;

            return true;

        }

        public static function isRunningOnDesktop():Boolean

        {

            init();

            return !_isMobileDevice;

        }

        // ****************************************************

        //

        //          Private Methods

        //

        // ****************************************************

        private static function init():void

        {

            if (_isInitialized)

                return;

            _isInitialized = true;

            _isMobileDevice = true;

            var operatingSystem:String = Capabilities.os;

            if (operatingSystem.indexOf("Windows") != -1)

            {

                switch (operatingSystem)

                {

                    case "Windows XP":

                    case "Windows 2000":

                    case "Windows NT":

                    case "Windows 7":

                    {

                        _isMobileDevice = false;

                        _osCategory = OS_CATEGORY__WINDOWS_DESKTOP;

                        break;

                    }

                    default:

                    {

                        _osCategory = OS_CATEGORY__UNKNOWN;

                        Log.fatal(Constant_AppConfiguration.APP_NAME + " does not currently support this operating system. (" + operatingSystem + ")");

                    }

                }

            }

            else if (operatingSystem.indexOf("iPhone") != -1)

            {

                _isMobileDevice = true;

                _osCategory = OS_CATEGORY__IOS;

            }

            else if (operatingSystem.indexOf("MacOS") != -1)

            {

                _isMobileDevice = false;

                _osCategory = OS_CATEGORY__MAC;

            }

            else if (operatingSystem.indexOf("Linux") != -1)

            {

                // This won't work properly if developing on Linux, but I've spent multiple minutes

                // trying to find out how to differentiate Android from other Linux versions, and

                // haven't found anything that I'm confident will work for future versions of Android.

                // Currently I get "Linux 2.6.32.9-g34b306d". I suspect that the "g" indicates "Google"

                // but have found nothing to support this idea.

                _isMobileDevice = true;

                _osCategory = OS_CATEGORY__ANDROID;

            }

            if (_isMobileDevice)

            {

                _appHeight = Capabilities.screenResolutionY;

                _appWidth = Capabilities.screenResolutionX;

            }

            else

            {

                _appHeight = 220;

                _appWidth = 360;

            }

            _dpi = Capabilities.screenDPI;

        }

    }

}

Translate