How to determine if an application is running as a mobile or desktop air applicaton?

≡放荡痞女 提交于 2019-12-06 01:43:58

ok this works:

public static function isAndroid():Boolean
{
    return (Capabilities.version.substr(0,3) == "AND");
}
public static function isIOS():Boolean
{
    return (Capabilities.version.substr(0,3) == "IOS");
}
 ... //is Blackberry

public static function isMobile():Boolean
{
    return (isAndroid() || isIOS()); // || isBlackberry()
}

You can use Capabilities.OS; however heed this warning from the docs:

Do not use Capabilities.os or Capabilities.manufacturer to determine a capability based on the operating system. Basing a capability on the operating system is a bad idea, since it can lead to problems if an application does not consider all potential target operating systems. Instead, use the property corresponding to the capability for which you are testing.

If you need to know whether you are running on mobile or desktop you should check for Capabilities.cpuArchitecture:

if(Capabilities.cpuArchitecture=="ARM") {

}

I'm not sure, But we can not convert FlexGlobals.topLevelApplicatinn into WindowedApplication in Mobile Application.

So, Mobile Applications can be from the following types:

1.TabbedViewNavigatorApplication - for Tabbed View Navigation Application

2.viewnavigatorapplication - view based navigation application

So as your application type you should try from above two options for conversion....

This test will work from a mobile app without needing to test for specific OS names (like Capabilities.os or Capabilities.version). It has the advantage of working consistently when debugging a mobile app on the desktop as well where Capabilities.os may not give you the answer you want:

import flash.utils.getDefinitionByName;
...

var hasWindowedApp:Boolean = false;
try
{
    hasWindowedApp = getDefinitionByName("spark.components.WindowedApplication") != null;
}
catch (error:ReferenceError)
{
}

if (!hasWindowedApp)
{
    try
    {
        hasWindowedApp = getDefinitionByName("mx.core.WindowedApplication") != null;
    }
    catch (error:ReferenceError)
    {
    }
}

This is the class I use for determine which os is it and if it's Mobile or not, of course this only covers Windows, Linux Android and iOS:

package com.fw3dlogical.utils {

    import flash.system.Capabilities;

    /**
     * Platform
     * @author Juan Fernando Velez
     */
    public class Platform {

            public static function get isWin():Boolean {
                return (Capabilities.version.indexOf("WIN") != -1);
            }

            public static function get isLinux():Boolean {
                return (Capabilities.version.indexOf("LNX") != -1);
            }

            public static function get isAndroid():Boolean {
                return (Capabilities.version.indexOf("AND") != -1);
            }

            public static function get isiOS():Boolean {
                return (Capabilities.version.indexOf("IOS") != -1);
            }

            public static function isMobile():Boolean {
                return (isAndroid() || isiOS());
            }

        }
    }
}

C# Function to check IOS(iPad, iPhone)

    public bool isIOS()
    {
        HttpContext context = HttpContext.Current;

        if (context.Request.ServerVariables["HTTP_USER_AGENT"] != null)
        {
            foreach (string s in new[] { "iPad", "iphone" })
            {
                if (context.Request.ServerVariables["HTTP_USER_AGENT"].ToLower().Contains(s.ToLower()))
                {
                    return true;
                }
            }
        }

        return false;
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!