Repository: ahand/mobileesp
Branch: master
Commit: c02055dbe9ba
Files: 20
Total size: 382.4 KB
Directory structure:
gitextract_t1__mu8f/
├── ASP_NET/
│ ├── Sub-Classed Page Technique/
│ │ ├── MDetectPage.cs
│ │ ├── MDetect_Test.aspx
│ │ └── MDetect_Test.aspx.cs
│ └── UserControl Technique/
│ ├── MDetectControl.cs
│ ├── MobileDetectControl.ascx
│ ├── MobileDetectControl.ascx.cs
│ ├── MobileDetectControl.ascx.designer.cs
│ ├── MobileDetectTestPage.aspx
│ ├── MobileDetectTestPage.aspx.cs
│ └── MobileDetectTestPage.aspx.designer.cs
├── Cpp/
│ └── mdetect.h
├── Java/
│ └── UAgentInfo.java
├── JavaScript/
│ └── mdetect.js
├── LICENSE
├── MobileESP_UA-Test-Strings/
│ ├── MobileESP UA Test Strings - UA Strings.csv
│ └── MobileESP UA Test Strings.xlsx
├── PHP/
│ └── mdetect.php
├── Python/
│ └── mdetect.py
├── README.md
└── composer.json
================================================
FILE CONTENTS
================================================
================================================
FILE: ASP_NET/Sub-Classed Page Technique/MDetectPage.cs
================================================
/* *******************************************
// Copyright 2010-2015, Anthony Hand
//
//
// File version 2015.05.13 (May 13, 2015)
// Updates:
// - Moved MobileESP to GitHub. https://github.com/ahand/mobileesp
// - Opera Mobile/Mini browser has the same UA string on multiple platforms and doesn't differentiate phone vs. tablet.
// - Removed DetectOperaAndroidPhone(). This method is no longer reliable.
// - Removed DetectOperaAndroidTablet(). This method is no longer reliable.
// - Added support for Windows Phone 10: variable and DetectWindowsPhone10()
// - Updated DetectWindowsPhone() to include WP10.
// - Added support for Firefox OS.
// - A variable plus DetectFirefoxOS(), DetectFirefoxOSPhone(), DetectFirefoxOSTablet()
// - NOTE: Firefox doesn't add UA tokens to definitively identify Firefox OS vs. their browsers on other mobile platforms.
// - Added support for Sailfish OS. Not enough info to add a tablet detection method at this time.
// - A variable plus DetectSailfish(), DetectSailfishPhone()
// - Added support for Ubuntu Mobile OS.
// - DetectUbuntu(), DetectUbuntuPhone(), DetectUbuntuTablet()
// - Added support for 2 smart TV OSes. They lack browsers but do have WebViews for use by HTML apps.
// - One variable for Samsung Tizen TVs, plus DetectTizenTV()
// - One variable for LG WebOS TVs, plus DetectWebOSTV()
// - Added DetectTizen(). Tests for “mobile” to disambiguate from Samsung Smart TVs.
// - Removed variables for obsolete devices: deviceHtcFlyer, deviceXoom.
// - Updated DetectAndroid(). No longer has a special test case for the HTC Flyer tablet.
// - Updated DetectAndroidPhone().
// - Updated internal detection code for Android.
// - No longer has a special test case for the HTC Flyer tablet.
// - Checks against DetectOperaMobile() on Android and reports here if relevant.
// - Updated DetectAndroidTablet().
// - No longer has a special test case for the HTC Flyer tablet.
// - Checks against DetectOperaMobile() on Android to exclude it from here.
// - DetectMeego(): Changed definition for this method. Now detects any Meego OS device, not just phones.
// - DetectMeegoPhone(): NEW. For Meego phones. Ought to detect Opera browsers on Meego, as well.
// - DetectTierIphone(): Added support for phones running Sailfish, Ubuntu and Firefox Mobile.
// - DetectTierTablet(): Added support for tablets running Ubuntu and Firefox Mobile.
// - DetectSmartphone(): Added support for Meego phones.
// - Caught this library up to the PHP, JavaScript and Java versions. Updates include:
// - Added support for Bada: a variable and DetectBada(). This detects any Bada OS device, but (almost) all are phones.
// - Refactored the Windows Phone delegate-related properties and features. Now fires for any Windows Phone, not just WP7.
// - The event fires now when DetectWindowsPhone() is true.
// - Added support for Windows Phone 8: DetectWindowsPhone8().
// - Updated DetectWindowsMobile(). Excludes any Windows Phone device, not just WP7.
// - Added support for BlackBerry 10 OS phones: DetectBlackBerry10Phone().
// - Updated DetectSonyMylo().
// - Updated DetectSmartphone() to sync with the other libraries.
// - Updated DetectTierIphone() to sync with the other libraries.
// - OnInit(EventArgs e): Fixed the user agent and httpaccept init logic.
// - Refactored the detection logic in DetectMobileQuick() and DetectMobileLong().
// - Moved a few detection tests for older browsers to Long.
//
//
//
// LICENSE INFORMATION
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific
// language governing permissions and limitations under the License.
//
//
// ABOUT THIS PROJECT
// Project Owner: Anthony Hand
// Email: anthony.hand@gmail.com
// Web Site: http://www.mobileesp.com
// Source Files: https://github.com/ahand/mobileesp
//
// Versions of this code are available for:
// PHP, JavaScript, Java, ASP.NET (C#), and Ruby
//
// *******************************************
*/
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
///
/// Subclass this page to inherit the built-in mobile device detection.
///
public class MDetectPage : System.Web.UI.Page
{
private string useragent = "";
private string httpaccept = "";
#region Fields - Detection Argument Values
//standardized values for detection arguments.
private const string dargsIphone = "iphone";
private const string dargsIpod = "ipod";
private const string dargsIpad = "ipad";
private const string dargsIphoneOrIpod = "iphoneoripod";
private const string dargsIos = "ios";
private const string dargsAndroid = "android";
private const string dargsAndroidPhone = "androidphone";
private const string dargsAndroidTablet = "androidtablet";
private const string dargsGoogleTV = "googletv";
private const string dargsWebKit = "webkit";
private const string dargsSymbianOS = "symbianos";
private const string dargsS60 = "series60";
private const string dargsWindowsPhone = "windowsphone";
private const string dargsWindowsMobile = "windowsmobile";
private const string dargsBlackBerry = "blackberry";
private const string dargsBlackBerryWebkit = "blackberrywebkit";
private const string dargsPalmOS = "palmos";
private const string dargsPalmWebOS = "webos";
private const string dargsWebOSTablet = "webostablet";
private const string dargsSmartphone = "smartphone";
private const string dargsBrewDevice = "brew";
private const string dargsDangerHiptop = "dangerhiptop";
private const string dargsOperaMobile = "operamobile";
private const string dargsWapWml = "wapwml";
private const string dargsKindle = "kindle";
private const string dargsMobileQuick = "mobilequick";
private const string dargsTierTablet = "tiertablet";
private const string dargsTierIphone = "tieriphone";
private const string dargsTierRichCss = "tierrichcss";
private const string dargsTierOtherPhones = "tierotherphones";
#endregion Fields - Detection Argument Values
#region Fields - User Agent Keyword Values
private const string engineWebKit = "WEBKIT";
private const string deviceIphone = "IPHONE";
private const string deviceIpod = "IPOD";
private const string deviceIpad = "IPAD";
private const string deviceMacPpc = "MACINTOSH"; //Used for disambiguation
private const string deviceAndroid = "ANDROID";
private const string deviceGoogleTV = "GOOGLETV";
private const string deviceNuvifone = "NUVIFONE"; //Garmin Nuvifone
private const string deviceBada = "BADA"; //Samsung's Bada OS
private const string deviceTizen = "TIZEN"; //Tizen OS
private const string deviceMeego = "MEEGO"; //Meego OS
private const string deviceSailfish = "SAILFISH"; //Sailfish OS
private const string deviceUbuntu = "UBUNTU"; //Ubuntu Mobile OS
private const string deviceSymbian = "SYMBIAN";
private const string deviceS60 = "SERIES60";
private const string deviceS70 = "SERIES70";
private const string deviceS80 = "SERIES80";
private const string deviceS90 = "SERIES90";
private const string deviceWinPhone7 = "WINDOWS PHONE OS 7";
private const string deviceWinPhone8 = "WINDOWS PHONE 8";
private const string deviceWinPhone10 = "WINDOWS PHONE 10";
private const string deviceWinMob = "WINDOWS CE";
private const string deviceWindows = "WINDOWS";
private const string deviceIeMob = "IEMOBILE";
private const string devicePpc = "PPC"; //Stands for PocketPC
private const string enginePie = "WM5 PIE"; //An old Windows Mobile browser
private const string deviceBB = "BLACKBERRY";
private const string deviceBB10 = "BB10"; //For the new BB 10 OS
private const string vndRIM = "VND.RIM"; //Detectable when BB devices emulate IE or Firefox
private const string deviceBBStorm = "BLACKBERRY95"; //Storm 1 and 2
private const string deviceBBBold = "BLACKBERRY97"; //Bold 97x0 (non-touch)
private const string deviceBBBoldTouch = "BLACKBERRY 99"; //Bold 99x0 (touchscreen)
private const string deviceBBTour = "BLACKBERRY96"; //Tour
private const string deviceBBCurve = "BLACKBERRY89"; //Curve2
private const string deviceBBCurveTouch = "BLACKBERRY 938"; //Curve Touch 9380
private const string deviceBBTorch = "BLACKBERRY 98"; //Torch
private const string deviceBBPlaybook = "PLAYBOOK"; //PlayBook tablet
private const string devicePalm = "PALM";
private const string deviceWebOS = "WEBOS"; //For Palm devices
private const string deviceWebOStv = "WEB0S"; //For LG TVs
private const string deviceWebOShp = "HPWOS"; //For HP's line of WebOS devices
private const string engineBlazer = "BLAZER"; //Old Palm
private const string engineXiino = "XIINO"; //Another old Palm
private const string deviceKindle = "KINDLE"; //Amazon Kindle, eInk one
private const string engineSilk = "SILK"; //Amazon's accelerated Silk browser for Kindle Fire
//Initialize private strings for mobile-specific content.
private const string vndwap = "VND.WAP";
private const string wml = "WML";
//Initialize private strings for other random devices and mobile browsers.
private const string deviceTablet = "TABLET"; //Generic term for slate and tablet devices
private const string deviceBrew = "BREW";
private const string deviceDanger = "DANGER";
private const string deviceHiptop = "HIPTOP";
private const string devicePlaystation = "PLAYSTATION";
private const string devicePlaystationVita = "VITA";
private const string deviceNintendoDs = "NITRO";
private const string deviceNintendo = "NINTENDO";
private const string deviceWii = "WII";
private const string deviceXbox = "XBOX";
private const string deviceArchos = "ARCHOS";
private const string engineFirefox = "FIREFOX"; //For Firefox OS
private const string engineOpera = "OPERA"; //Popular browser
private const string engineNetfront = "NETFRONT"; //Common embedded OS browser
private const string engineUpBrowser = "UP.BROWSER"; //common on some phones
private const string engineOpenWeb = "OPENWEB"; //Transcoding by OpenWave server
private const string deviceMidp = "MIDP"; //a mobile Java technology
private const string uplink = "UP.LINK";
private const string engineTelecaQ = "TELECA Q"; //a modern feature phone browser
private const string devicePda = "PDA"; //some devices report themselves as PDAs
private const string mini = "MINI"; //Some mobile browsers put "mini" in their names.
private const string mobile = "MOBILE"; //Some mobile browsers put "mobile" in their user agent private strings.
private const string mobi = "MOBI"; //Some mobile browsers put "mobi" in their user agent private strings.
//Smart TV strings
private const string smartTV1 = "SMART-TV"; //Samsung Tizen smart TVs
private const string smartTV2 = "SMARTTV"; //LG WebOS smart TVs
//Use Maemo, Tablet, and Linux to test for Nokia"s Internet Tablets.
private const string maemo = "MAEMO";
private const string linux = "LINUX";
private const string qtembedded = "QT EMBEDDED"; //for Sony Mylo
private const string mylocom2 = "COM2"; //for Sony Mylo also
//In some UserAgents, the only clue is the manufacturer.
private const string manuSonyEricsson = "SONYERICSSON";
private const string manuericsson = "ERICSSON";
private const string manuSamsung1 = "SEC-SGH";
private const string manuSony = "SONY";
private const string manuHtc = "HTC"; //Popular Android and WinMo manufacturer
//In some UserAgents, the only clue is the operator.
private const string svcDocomo = "DOCOMO";
private const string svcKddi = "KDDI";
private const string svcVodafone = "VODAFONE";
//Disambiguation strings.
private const string disUpdate = "UPDATE"; //pda vs. update
#endregion Fields - User Agent Keyword Values
///
/// To instantiate a WebPage sub-class with built-in
/// mobile device detection delegates and events.
///
public MDetectPage()
{
}
///
/// To run the device detection methods andd fire
/// any existing OnDetectXXX events.
///
public void FireEvents()
{
if (useragent == "" && httpaccept == "")
{
useragent = (Request.ServerVariables["HTTP_USER_AGENT"] ?? "").ToUpper();
httpaccept = (Request.ServerVariables["HTTP_ACCEPT"] ?? "").ToUpper();
}
#region Event Fire Methods
MDetectArgs mda = null;
if (this.DetectIpod())
{
mda = new MDetectArgs(dargsIpod);
if (this.OnDetectIpod != null)
{
this.OnDetectIpod(this, mda);
}
}
if (this.DetectIpad())
{
mda = new MDetectArgs(dargsIpad);
if (this.OnDetectIpad != null)
{
this.OnDetectIpad(this, mda);
}
}
if (this.DetectIphone())
{
mda = new MDetectArgs(dargsIphone);
if (this.OnDetectIphone != null)
{
this.OnDetectIphone(this, mda);
}
}
if (this.DetectIphoneOrIpod())
{
mda = new MDetectArgs(dargsIphoneOrIpod);
if (this.OnDetectDetectIPhoneOrIpod != null)
{
this.OnDetectDetectIPhoneOrIpod(this, mda);
}
}
if (this.DetectIos())
{
mda = new MDetectArgs(dargsIos);
if (this.OnDetectIos != null)
{
this.OnDetectIos(this, mda);
}
}
if (this.DetectAndroid())
{
mda = new MDetectArgs(dargsAndroid);
if (this.OnDetectAndroid != null)
{
this.OnDetectAndroid(this, mda);
}
}
if (this.DetectAndroidPhone())
{
mda = new MDetectArgs(dargsAndroidPhone);
if (this.OnDetectAndroidPhone != null)
{
this.OnDetectAndroidPhone(this, mda);
}
}
if (this.DetectAndroidTablet())
{
mda = new MDetectArgs(dargsAndroidTablet);
if (this.OnDetectAndroidTablet != null)
{
this.OnDetectAndroidTablet(this, mda);
}
}
if (this.DetectGoogleTV())
{
mda = new MDetectArgs(dargsGoogleTV);
if (this.OnDetectGoogleTV != null)
{
this.OnDetectGoogleTV(this, mda);
}
}
if (this.DetectWebkit())
{
mda = new MDetectArgs(dargsWebKit);
if (this.OnDetectWebkit != null)
{
this.OnDetectWebkit(this, mda);
}
}
if (this.DetectS60OssBrowser())
{
mda = new MDetectArgs(dargsS60);
if (this.OnDetectS60OssBrowser != null)
{
this.OnDetectS60OssBrowser(this, mda);
}
}
if (this.DetectSymbianOS())
{
mda = new MDetectArgs(dargsSymbianOS);
if (this.OnDetectSymbianOS != null)
{
this.OnDetectSymbianOS(this, mda);
}
}
if (this.DetectWindowsPhone())
{
mda = new MDetectArgs(dargsWindowsPhone);
if (this.OnDetectWindowsPhone != null)
{
this.OnDetectWindowsPhone(this, mda);
}
}
if (this.DetectWindowsMobile())
{
mda = new MDetectArgs(dargsWindowsMobile);
if (this.OnDetectWindowsMobile != null)
{
this.OnDetectWindowsMobile(this, mda);
}
}
if (this.DetectBlackBerry())
{
mda = new MDetectArgs(dargsBlackBerryWebkit);
if (this.OnDetectBlackBerry != null)
{
this.OnDetectBlackBerry(this, mda);
}
}
if (this.DetectBlackBerryWebKit())
{
mda = new MDetectArgs(dargsBlackBerryWebkit);
if (this.OnDetectBlackBerryWebkit != null)
{
this.OnDetectBlackBerryWebkit(this, mda);
}
}
if (this.DetectPalmOS())
{
mda = new MDetectArgs(dargsPalmOS);
if (this.OnDetectPalmOS != null)
{
this.OnDetectPalmOS(this, mda);
}
}
if (this.DetectPalmWebOS())
{
mda = new MDetectArgs(dargsPalmWebOS);
if (this.OnDetectPalmWebOS != null)
{
this.OnDetectPalmWebOS(this, mda);
}
}
if (this.DetectWebOSTablet())
{
mda = new MDetectArgs(dargsWebOSTablet);
if (this.OnDetectWebOSTablet != null)
{
this.OnDetectWebOSTablet(this, mda);
}
}
if (this.DetectSmartphone())
{
mda = new MDetectArgs(dargsSmartphone);
if (this.OnDetectSmartphone != null)
{
this.OnDetectSmartphone(this, mda);
}
}
if (this.DetectBrewDevice())
{
mda = new MDetectArgs(dargsBrewDevice);
if (this.OnDetectBrewDevice != null)
{
this.OnDetectBrewDevice(this, mda);
}
}
if (this.DetectDangerHiptop())
{
mda = new MDetectArgs(dargsDangerHiptop);
if (this.OnDetectDangerHiptop != null)
{
this.OnDetectDangerHiptop(this, mda);
}
}
if (this.DetectOperaMobile())
{
mda = new MDetectArgs(dargsOperaMobile);
if (this.OnDetectOperaMobile != null)
{
this.OnDetectOperaMobile(this, mda);
}
}
if (this.DetectWapWml())
{
mda = new MDetectArgs(dargsWapWml);
if (this.OnDetectWapWml != null)
{
this.OnDetectWapWml(this, mda);
}
}
if (this.DetectKindle())
{
mda = new MDetectArgs(dargsKindle);
if (this.OnDetectKindle != null)
{
this.OnDetectKindle(this, mda);
}
}
if (this.DetectMobileQuick())
{
mda = new MDetectArgs(dargsMobileQuick);
if (this.OnDetectMobileQuick != null)
{
this.OnDetectMobileQuick(this, mda);
}
}
if (this.DetectTierTablet())
{
mda = new MDetectArgs(dargsTierTablet);
if (this.OnDetectTierTablet != null)
{
this.OnDetectTierTablet(this, mda);
}
}
if (this.DetectTierIphone())
{
mda = new MDetectArgs(dargsTierIphone);
if (this.OnDetectTierIphone != null)
{
this.OnDetectTierIphone(this, mda);
}
}
if (this.DetectTierRichCss())
{
mda = new MDetectArgs(dargsTierRichCss);
if (this.OnDetectTierRichCss != null)
{
this.OnDetectTierRichCss(this, mda);
}
}
if (this.DetectTierOtherPhones())
{
mda = new MDetectArgs(dargsTierOtherPhones);
if (this.OnDetectTierOtherPhones != null)
{
this.OnDetectTierOtherPhones(this, mda);
}
}
#endregion Event Fire Methods
}
public class MDetectArgs : EventArgs
{
public MDetectArgs(string type)
{
this.Type = type;
}
public readonly string Type;
}
#region Mobile Device Detection Methods
//**************************
// Detects if the current device is an iPod Touch.
public bool DetectIpod()
{
if (useragent.IndexOf(deviceIpod)!= -1)
return true;
else
return false;
}
//Ipod delegate
public delegate void DetectIpodHandler(object page, MDetectArgs args);
public event DetectIpodHandler OnDetectIpod;
//**************************
// Detects if the current device is an iPad tablet.
public bool DetectIpad()
{
if (useragent.IndexOf(deviceIpad) != -1 && DetectWebkit())
return true;
else
return false;
}
//Ipod delegate
public delegate void DetectIpadHandler(object page, MDetectArgs args);
public event DetectIpadHandler OnDetectIpad;
//**************************
// Detects if the current device is an iPhone.
public bool DetectIphone()
{
if (useragent.IndexOf(deviceIphone)!= -1)
{
//The iPad and iPod touch say they're an iPhone! So let's disambiguate.
if (DetectIpad() || DetectIpod())
{
return false;
}
else
return true;
}
else
return false;
}
//IPhone delegate
public delegate void DetectIphoneHandler(object page, MDetectArgs args);
public event DetectIphoneHandler OnDetectIphone;
//**************************
// Detects if the current device is an iPhone or iPod Touch.
public bool DetectIphoneOrIpod()
{
//We repeat the searches here because some iPods may report themselves as an iPhone, which would be okay.
if (useragent.IndexOf(deviceIphone)!= -1 ||
useragent.IndexOf(deviceIpod)!= -1)
return true;
else
return false;
}
//IPhoneOrIpod delegate
public delegate void DetectIPhoneOrIpodHandler(object page, MDetectArgs args);
public event DetectIPhoneOrIpodHandler OnDetectDetectIPhoneOrIpod;
//**************************
// Detects *any* iOS device: iPhone, iPod Touch, iPad.
public bool DetectIos()
{
if (DetectIphoneOrIpod() || DetectIpad())
return true;
else
return false;
}
//Ios delegate
public delegate void DetectIosHandler(object page, MDetectArgs args);
public event DetectIosHandler OnDetectIos;
//**************************
// Detects *any* Android OS-based device: phone, tablet, and multi-media player.
// Also detects Google TV.
public bool DetectAndroid()
{
if ((useragent.IndexOf(deviceAndroid) != -1) ||
DetectGoogleTV())
return true;
return false;
}
//Android delegate
public delegate void DetectAndroidHandler(object page, MDetectArgs args);
public event DetectAndroidHandler OnDetectAndroid;
//**************************
// Detects if the current device is a (small-ish) Android OS-based device
// used for calling and/or multi-media (like a Samsung Galaxy Player).
// Google says these devices will have 'Android' AND 'mobile' in user agent.
// Ignores tablets (Honeycomb and later).
public bool DetectAndroidPhone()
{
//First, let's make sure we're on an Android device.
if (!DetectAndroid())
return false;
//If it's Android and has 'mobile' in it, Google says it's a phone.
if (useragent.IndexOf(mobile) != -1)
return true;
//Special check for Android devices with Opera Mobile/Mini. They should report here.
if (DetectOperaMobile())
return true;
return false;
}
//Android Phone delegate
public delegate void DetectAndroidPhoneHandler(object page, MDetectArgs args);
public event DetectAndroidPhoneHandler OnDetectAndroidPhone;
//**************************
// Detects if the current device is a (self-reported) Android tablet.
// Google says these devices will have 'Android' and NOT 'mobile' in their user agent.
public bool DetectAndroidTablet()
{
//First, let's make sure we're on an Android device.
if (!DetectAndroid())
return false;
//Special check for Android devices with Opera Mobile/Mini. They should NOT report here.
if (DetectOperaMobile())
return false;
//Otherwise, if it's Android and does NOT have 'mobile' in it, Google says it's a tablet.
if (useragent.IndexOf(mobile) > -1)
return false;
else
return true;
}
//Android Tablet delegate
public delegate void DetectAndroidTabletHandler(object page, MDetectArgs args);
public event DetectAndroidTabletHandler OnDetectAndroidTablet;
//**************************
// Detects if the current device is a GoogleTV device.
public bool DetectGoogleTV()
{
if (useragent.IndexOf(deviceGoogleTV) != -1)
return true;
else
return false;
}
//GoogleTV delegate
public delegate void DetectGoogleTVHandler(object page, MDetectArgs args);
public event DetectGoogleTVHandler OnDetectGoogleTV;
//**************************
// Detects if the current device is an Android OS-based device and
// the browser is based on WebKit.
public bool DetectAndroidWebKit()
{
if (DetectAndroid() && DetectWebkit())
return true;
else
return false;
}
//**************************
// Detects if the current browser is based on WebKit.
public bool DetectWebkit()
{
if (useragent.IndexOf(engineWebKit)!= -1)
return true;
else
return false;
}
//Webkit delegate
public delegate void DetectWebkitHandler(object page, MDetectArgs args);
public event DetectWebkitHandler OnDetectWebkit;
//**************************
// Detects if the current browser is the Nokia S60 Open Source Browser.
public bool DetectS60OssBrowser()
{
//First, test for WebKit, then make sure it's either Symbian or S60.
if (DetectWebkit())
{
if (useragent.IndexOf(deviceSymbian)!= -1 ||
useragent.IndexOf(deviceS60)!= -1)
{
return true;
}
else
return false;
}
else
return false;
}
//S60OssBrowser delegate
public delegate void DetectS60OssBrowserHandler(object page, MDetectArgs args);
public event DetectS60OssBrowserHandler OnDetectS60OssBrowser;
//**************************
// Detects if the current device is any Symbian OS-based device,
// including older S60, Series 70, Series 80, Series 90, and UIQ,
// or other browsers running on these devices.
public bool DetectSymbianOS()
{
if (useragent.IndexOf(deviceSymbian)!= -1 ||
useragent.IndexOf(deviceS60)!= -1 ||
useragent.IndexOf(deviceS70)!= -1 ||
useragent.IndexOf(deviceS80)!= -1 ||
useragent.IndexOf(deviceS90)!= -1)
return true;
else
return false;
}
//SymbianOS delegate
public delegate void DetectSymbianOSHandler(object page, MDetectArgs args);
public event DetectSymbianOSHandler OnDetectSymbianOS;
//**************************
// Detects if the current browser is a
// Windows Phone 7, 8, or 10 device.
public bool DetectWindowsPhone()
{
if (DetectWindowsPhone7() ||
DetectWindowsPhone8() ||
DetectWindowsPhone10())
return true;
return false;
}
//WindowsPhone delegate
public delegate void DetectWindowsPhoneHandler(object page, MDetectArgs args);
public event DetectWindowsPhoneHandler OnDetectWindowsPhone;
//**************************
// Detects if the current browser is a
// Windows Phone 7 device.
public bool DetectWindowsPhone7()
{
if (useragent.IndexOf(deviceWinPhone7) != -1)
return true;
else
return false;
}
//**************************
// Detects if the current browser is a
// Windows Phone 8 device.
public bool DetectWindowsPhone8()
{
if (useragent.IndexOf(deviceWinPhone8) != -1)
return true;
else
return false;
}
//**************************
// Detects if the current browser is a
// Windows Phone 10 device.
public bool DetectWindowsPhone10()
{
if (useragent.IndexOf(deviceWinPhone10) != -1)
return true;
else
return false;
}
//**************************
// Detects if the current browser is a Windows Mobile device.
// Excludes Windows Phone devices.
// Focuses on Windows Mobile 6.xx and earlier.
public bool DetectWindowsMobile()
{
//Exclude new Windows Phone.
if (DetectWindowsPhone())
return false;
//Most devices use 'Windows CE', but some report 'iemobile'
// and some older ones report as 'PIE' for Pocket IE.
if (useragent.IndexOf(deviceWinMob)!= -1 ||
useragent.IndexOf(deviceIeMob)!= -1 ||
useragent.IndexOf(enginePie) != -1)
return true;
//Test for Windows Mobile PPC but not old Macintosh PowerPC.
if (useragent.IndexOf(devicePpc) != -1 &&
!(useragent.IndexOf(deviceMacPpc) != -1))
return true;
//Test for certain Windwos Mobile-based HTC devices.
if (useragent.IndexOf(manuHtc) != -1 &&
useragent.IndexOf(deviceWindows) != -1)
return true;
if (DetectWapWml() == true &&
useragent.IndexOf(deviceWindows)!= -1)
return true;
else
return false;
}
//WindowsMobile delegate
public delegate void DetectWindowsMobileHandler(object page, MDetectArgs args);
public event DetectWindowsMobileHandler OnDetectWindowsMobile;
//**************************
// Detects if the current browser is any BlackBerry device.
// Includes the PlayBook.
public bool DetectBlackBerry()
{
if ((useragent.IndexOf(deviceBB)!= -1) ||
(httpaccept.IndexOf(vndRIM)!= -1))
return true;
else
return false;
}
//BlackBerry delegate
public delegate void DetectBlackBerryHandler(object page, MDetectArgs args);
public event DetectBlackBerryHandler OnDetectBlackBerry;
//**************************
// Detects if the current browser is a BlackBerry 10 OS phone.
// Excludes tablets.
public bool DetectBlackBerry10Phone()
{
if (useragent.IndexOf(deviceBB10) != -1 &&
useragent.IndexOf(mobile) != -1)
return true;
else
return false;
}
//**************************
// Detects if the current browser is on a BlackBerry tablet device.
// Example: PlayBook
public bool DetectBlackBerryTablet()
{
if (useragent.IndexOf(deviceBBPlaybook) != -1)
return true;
else
return false;
}
//**************************
// Detects if the current browser is a BlackBerry device AND uses a
// WebKit-based browser. These are signatures for the new BlackBerry OS 6.
// Examples: Torch. Includes the Playbook.
public bool DetectBlackBerryWebKit()
{
if (DetectBlackBerry() && DetectWebkit())
return true;
else
return false;
}
//BlackBerry Webkit delegate
public delegate void DetectBlackBerryWebkitHandler(object page, MDetectArgs args);
public event DetectBlackBerryWebkitHandler OnDetectBlackBerryWebkit;
//**************************
// Detects if the current browser is a BlackBerry Touch
// device, such as the Storm, Torch, and Bold Touch. Excludes the Playbook.
public bool DetectBlackBerryTouch()
{
if (DetectBlackBerry() &&
(useragent.IndexOf(deviceBBStorm) != -1 ||
useragent.IndexOf(deviceBBTorch) != -1 ||
useragent.IndexOf(deviceBBBoldTouch) != -1 ||
useragent.IndexOf(deviceBBCurveTouch) != -1))
return true;
else
return false;
}
//**************************
// Detects if the current browser is a BlackBerry device AND
// has a more capable recent browser. Excludes the Playbook.
// Examples, Storm, Bold, Tour, Curve2
// Excludes the new BlackBerry OS 6 and 7 browser!!
public bool DetectBlackBerryHigh()
{
//Disambiguate for BlackBerry OS 6 or 7 (WebKit) browser
if (DetectBlackBerryWebKit())
return false;
if (DetectBlackBerry())
{
if (DetectBlackBerryTouch() ||
useragent.IndexOf(deviceBBBold) != -1 ||
useragent.IndexOf(deviceBBTour) != -1 ||
useragent.IndexOf(deviceBBCurve) != -1)
return true;
else
return false;
}
else
return false;
}
//**************************
// Detects if the current browser is a BlackBerry device AND
// has an older, less capable browser.
// Examples: Pearl, 8800, Curve1.
public bool DetectBlackBerryLow()
{
if (DetectBlackBerry())
{
//Assume that if it's not in the High tier, then it's Low.
if (DetectBlackBerryHigh() || DetectBlackBerryWebKit())
return false;
else
return true;
}
else
return false;
}
//**************************
// Detects if the current browser is on a PalmOS device.
public bool DetectPalmOS()
{
//Most devices nowadays report as 'Palm', but some older ones reported as Blazer or Xiino.
if (useragent.IndexOf(devicePalm) != -1 ||
useragent.IndexOf(engineBlazer) != -1 ||
useragent.IndexOf(engineXiino) != -1)
{
//Make sure it's not WebOS first
if (DetectPalmWebOS() == true)
return false;
else
return true;
}
else
return false;
}
//PalmOS delegate
public delegate void DetectPalmOSHandler(object page, MDetectArgs args);
public event DetectPalmOSHandler OnDetectPalmOS;
//**************************
// Detects if the current browser is on a Palm device
// running the new WebOS.
public bool DetectPalmWebOS()
{
if (useragent.IndexOf(deviceWebOS) != -1)
return true;
else
return false;
}
//PalmWebOS delegate
public delegate void DetectPalmWebOSHandler(object page, MDetectArgs args);
public event DetectPalmWebOSHandler OnDetectPalmWebOS;
//**************************
// Detects if the current browser is on an HP tablet running WebOS.
public bool DetectWebOSTablet()
{
if (useragent.IndexOf(deviceWebOShp) != -1 &&
useragent.IndexOf(deviceTablet) != -1)
{
return true;
}
else
return false;
}
//WebOS tablet delegate
public delegate void DetectWebOSTabletHandler(object page, MDetectArgs args);
public event DetectWebOSTabletHandler OnDetectWebOSTablet;
//**************************
// Detects if the current browser is on a WebOS smart TV.
public bool DetectWebOSTV()
{
if (useragent.IndexOf(deviceWebOStv) != -1 &&
useragent.IndexOf(smartTV2) != -1)
{
return true;
}
else
return false;
}
//**************************
// Detects if the current browser is Opera Mobile or Mini.
public bool DetectOperaMobile()
{
if (useragent.IndexOf(engineOpera)!= -1)
{
if ((useragent.IndexOf(mini)!= -1) ||
(useragent.IndexOf(mobi)!= -1))
{
return true;
}
else
return false;
}
else
return false;
}
//Opera Mobile delegate
public delegate void DetectOperaMobileHandler(object page, MDetectArgs args);
public event DetectOperaMobileHandler OnDetectOperaMobile;
//**************************
// Detects if the current browser is a
// Garmin Nuvifone.
public bool DetectGarminNuvifone()
{
if (useragent.IndexOf(deviceNuvifone) != -1)
return true;
else
return false;
}
//**************************
// Detects a device running the Bada OS from Samsung.
public bool DetectBada()
{
if (useragent.IndexOf(deviceBada) != -1)
{
return true;
}
else
return false;
}
//**************************
// Detects a device running the Tizen smartphone OS.
public bool DetectTizen()
{
if (useragent.IndexOf(deviceTizen) != -1 &&
useragent.IndexOf(mobile) != -1)
{
return true;
}
else
return false;
}
//**************************
// Detects if the current browser is on a Tizen smart TV.
public bool DetectTizenTV()
{
if (useragent.IndexOf(deviceTizen) != -1 &&
useragent.IndexOf(smartTV1) != -1)
{
return true;
}
else
return false;
}
//**************************
// Detects a device running the Meego OS.
public bool DetectMeego()
{
if (useragent.IndexOf(deviceMeego) != -1)
{
return true;
}
else
return false;
}
//**************************
// Detects a phone running the Meego OS.
public bool DetectMeegoPhone()
{
if (useragent.IndexOf(deviceMeego) != -1 &&
useragent.IndexOf(mobile) != -1)
{
return true;
}
else
return false;
}
//**************************
// Detects a mobile device (probably) running the Firefox OS.
public bool DetectFirefoxOS()
{
if (DetectFirefoxOSPhone() || DetectFirefoxOSTablet())
return true;
return false;
}
//**************************
// Detects a phone (probably) running the Firefox OS.
public bool DetectFirefoxOSPhone()
{
//First, let's make sure we're NOT on another major mobile OS.
if (DetectIos() ||
DetectAndroid() ||
DetectSailfish())
return false;
if ((useragent.IndexOf(engineFirefox) != -1) &&
(useragent.IndexOf(mobile) != -1))
return true;
return false;
}
//**************************
// Detects a tablet (probably) running the Firefox OS.
public bool DetectFirefoxOSTablet()
{
//First, let's make sure we're NOT on another major mobile OS.
if (DetectIos() ||
DetectAndroid() ||
DetectSailfish())
return false;
if ((useragent.IndexOf(engineFirefox) != -1) &&
(useragent.IndexOf(deviceTablet) != -1))
return true;
return false;
}
//**************************
// Detects a device running the Sailfish OS.
public bool DetectSailfish()
{
if (useragent.IndexOf(deviceSailfish) != -1)
return true;
else
return false;
}
//**************************
// Detects a phone running the Sailfish OS.
public bool DetectSailfishPhone()
{
if (DetectSailfish() &&
(useragent.IndexOf(mobile) != -1))
return true;
return false;
}
//**************************
// Detects a mobile device running the Ubuntu Mobile OS.
public bool DetectUbuntu()
{
if (DetectUbuntuPhone() || DetectUbuntuTablet())
return true;
return false;
}
//**************************
// Detects a phone running the Ubuntu Mobile OS.
public bool DetectUbuntuPhone()
{
if ((useragent.IndexOf(deviceUbuntu) != -1) &&
(useragent.IndexOf(mobile) != -1))
return true;
return false;
}
//**************************
// Detects a tablet running the Ubuntu Mobile OS.
public bool DetectUbuntuTablet()
{
if ((useragent.IndexOf(deviceUbuntu) != -1) &&
(useragent.IndexOf(deviceTablet) != -1))
return true;
return false;
}
//**************************
// Detects whether the device is a Brew-powered device.
public bool DetectBrewDevice()
{
if (useragent.IndexOf(deviceBrew)!= -1)
return true;
else
return false;
}
//BrewDevice delegate
public delegate void DetectBrewDeviceHandler(object page, MDetectArgs args);
public event DetectBrewDeviceHandler OnDetectBrewDevice;
//**************************
// Detects the Danger Hiptop device.
public bool DetectDangerHiptop()
{
if (useragent.IndexOf(deviceDanger)!= -1 ||
useragent.IndexOf(deviceHiptop)!= -1)
return true;
else
return false;
}
//DangerHiptop delegate
public delegate void DetectDangerHiptopHandler(object page, MDetectArgs args);
public event DetectDangerHiptopHandler OnDetectDangerHiptop;
//**************************
// Detects whether the device supports WAP or WML.
public bool DetectWapWml()
{
if (httpaccept.IndexOf(vndwap)!= -1 ||
httpaccept.IndexOf(wml)!= -1)
return true;
else
return false;
}
//WapWml delegate
public delegate void DetectWapWmlHandler(object page, MDetectArgs args);
public event DetectWapWmlHandler OnDetectWapWml;
//**************************
// Detects if the current device is an Amazon Kindle (eInk devices only).
// Note: For the Kindle Fire, use the normal Android methods.
public bool DetectKindle()
{
if (useragent.IndexOf(deviceKindle) != -1 &&
!DetectAndroid())
return true;
else
return false;
}
//Kindle delegate
public delegate void DetectKindleHandler(object page, MDetectArgs args);
public event DetectKindleHandler OnDetectKindle;
//**************************
// Detects if the current Amazon device is using the Silk Browser.
// Note: Typically used by the the Kindle Fire.
public bool DetectAmazonSilk()
{
if (useragent.IndexOf(engineSilk) != -1)
return true;
else
return false;
}
//**************************
// Detects if the current device is a Sony Playstation.
public bool DetectSonyPlaystation()
{
if (useragent.IndexOf(devicePlaystation)!= -1)
return true;
else
return false;
}
//**************************
// Detects if the current device is a handheld gaming device with
// a touchscreen and modern iPhone-class browser. Includes the Playstation Vita.
public bool DetectGamingHandheld()
{
if (useragent.IndexOf(devicePlaystation)!= -1 &&
useragent.IndexOf(devicePlaystationVita)!= -1)
return true;
else
return false;
}
//**************************
// Detects if the current device is a Nintendo game device.
public bool DetectNintendo()
{
if (useragent.IndexOf(deviceNintendo)!= -1 ||
useragent.IndexOf(deviceWii)!= -1 ||
useragent.IndexOf(deviceNintendoDs)!= -1)
return true;
else
return false;
}
//**************************
// Detects if the current device is a Microsoft Xbox.
public bool DetectXbox()
{
if (useragent.IndexOf(deviceXbox)!= -1)
return true;
else
return false;
}
//**************************
// Detects if the current device is an Internet-capable game console.
public bool DetectGameConsole()
{
if (DetectSonyPlaystation())
return true;
else if (DetectNintendo())
return true;
else if (DetectXbox())
return true;
else
return false;
}
//**************************
// Detects if the current device supports MIDP, a mobile Java technology.
public bool DetectMidpCapable()
{
if (useragent.IndexOf(deviceMidp)!= -1 ||
httpaccept.IndexOf(deviceMidp)!= -1)
return true;
else
return false;
}
//**************************
// Detects if the current device is on one of the Maemo-based Nokia Internet Tablets.
public bool DetectMaemoTablet()
{
if (useragent.IndexOf(maemo)!= -1)
return true;
//For Nokia N810, must be Linux + Tablet, or else it could be something else.
else if (useragent.IndexOf(linux)!= -1 &&
useragent.IndexOf(deviceTablet) != -1 &&
!DetectWebOSTablet() &&
!DetectAndroid())
return true;
else
return false;
}
//**************************
// Detects if the current device is an Archos media player/Internet tablet.
public bool DetectArchos()
{
if (useragent.IndexOf(deviceArchos)!= -1)
return true;
else
return false;
}
//**************************
// Detects if the current browser is a Sony Mylo device.
public bool DetectSonyMylo()
{
if ((useragent.IndexOf(manuSony)!= -1) &&
((useragent.IndexOf(qtembedded)!= -1) ||
(useragent.IndexOf(mylocom2)!= -1)))
return true;
return false;
}
//*****************************
// Device Classes
//*****************************
//**************************
// Check to see whether the device is any device
// in the 'smartphone' category.
// Note: It's better to use DetectTierIphone() for modern touchscreen devices.
public bool DetectSmartphone()
{
if (DetectTierIphone() ||
DetectS60OssBrowser() ||
DetectSymbianOS() ||
DetectWindowsMobile() ||
DetectBlackBerry() ||
DetectMeegoPhone() ||
DetectPalmOS())
return true;
else
return false;
}
//DetectSmartphone delegate
public delegate void DetectSmartphoneHandler(object page, MDetectArgs args);
public event DetectSmartphoneHandler OnDetectSmartphone;
//**************************
// Detects if the current device is a mobile device.
// This method catches most of the popular modern devices.
// Excludes Apple iPads and other modern tablets.
public bool DetectMobileQuick()
{
//Let's exclude tablets
if (DetectTierTablet())
return false;
//Most mobile browsing is done on smartphones
if (DetectSmartphone())
return true;
//Catch-all for many mobile devices
if (useragent.IndexOf(mobile) != -1)
return true;
if (DetectOperaMobile())
return true;
//We also look for Kindle devices
if (DetectKindle() ||
DetectAmazonSilk())
return true;
if (DetectWapWml() ||
DetectMidpCapable() ||
DetectBrewDevice())
return true;
if ((useragent.IndexOf(engineNetfront) != -1) ||
(useragent.IndexOf(engineUpBrowser) != -1))
return true;
return false;
}
//DetectMobileQuick delegate
public delegate void DetectMobileQuickHandler(object page, MDetectArgs args);
public event DetectMobileQuickHandler OnDetectMobileQuick;
//**************************
// The longer and more thorough way to detect for a mobile device.
// Will probably detect most feature phones,
// smartphone-class devices, Internet Tablets,
// Internet-enabled game consoles, etc.
// This ought to catch a lot of the more obscure and older devices, also --
// but no promises on thoroughness!
public bool DetectMobileLong()
{
if (DetectMobileQuick())
return true;
if (DetectGameConsole())
return true;
if (DetectDangerHiptop() ||
DetectMaemoTablet() ||
DetectSonyMylo() ||
DetectArchos())
return true;
if ((useragent.IndexOf(devicePda) != -1) &&
(useragent.IndexOf(disUpdate) != -1))
return true;
//Detect older phones from certain manufacturers and operators.
if ((useragent.IndexOf(uplink) != -1) ||
(useragent.IndexOf(engineOpenWeb) != -1) ||
(useragent.IndexOf(manuSamsung1) != -1) ||
(useragent.IndexOf(manuSonyEricsson) != -1) ||
(useragent.IndexOf(manuericsson) != -1) ||
(useragent.IndexOf(svcDocomo) != -1) ||
(useragent.IndexOf(svcKddi) != -1) ||
(useragent.IndexOf(svcVodafone) != -1))
return true;
return false;
}
//*****************************
// For Mobile Web Site Design
//*****************************
//**************************
// The quick way to detect for a tier of devices.
// This method detects for the new generation of
// HTML 5 capable, larger screen tablets.
// Includes iPad, Android (e.g., Xoom), BB Playbook, WebOS, etc.
public bool DetectTierTablet()
{
if (DetectIpad()
|| DetectAndroidTablet()
|| DetectBlackBerryTablet()
|| DetectFirefoxOSTablet()
|| DetectUbuntuTablet()
|| DetectWebOSTablet())
return true;
else
return false;
}
//DetectTierTablet delegate
public delegate void DetectTierTabletHandler(object page, MDetectArgs args);
public event DetectTierTabletHandler OnDetectTierTablet;
//**************************
// The quick way to detect for a tier of devices.
// This method detects for devices which can
// display iPhone-optimized web content.
// Includes iPhone, iPod Touch, Android, Windows Phone, BB10, Playstation Vita, etc.
public bool DetectTierIphone()
{
if (DetectIphoneOrIpod() ||
DetectAndroidPhone() ||
DetectWindowsPhone() ||
DetectBlackBerry10Phone() ||
DetectPalmWebOS() ||
DetectBada() ||
DetectTizen() ||
DetectFirefoxOSPhone() ||
DetectSailfishPhone() ||
DetectUbuntuPhone() ||
DetectGamingHandheld())
return true;
else
return false;
}
//DetectTierIphone delegate
public delegate void DetectTierIphoneHandler(object page, MDetectArgs args);
public event DetectTierIphoneHandler OnDetectTierIphone;
//**************************
// The quick way to detect for a tier of devices.
// This method detects for devices which are likely to be capable
// of viewing CSS content optimized for the iPhone,
// but may not necessarily support JavaScript.
// Excludes all iPhone Tier devices.
public bool DetectTierRichCss()
{
if (DetectMobileQuick())
{
//Exclude iPhone Tier and e-Ink Kindle devices
if (DetectTierIphone() || DetectKindle())
return false;
if (DetectWebkit() ||
DetectS60OssBrowser())
return true;
//Note: 'High' BlackBerry devices ONLY
if (DetectBlackBerryHigh() == true)
return true;
//Older Windows 'Mobile' isn't good enough for iPhone Tier.
if (DetectWindowsMobile() == true)
return true;
if (useragent.IndexOf(engineTelecaQ) != -1)
return true;
else
return false;
}
else
return false;
}
//DetectTierRichCss delegate
public delegate void DetectTierRichCssHandler(object page, MDetectArgs args);
public event DetectTierRichCssHandler OnDetectTierRichCss;
//**************************
// The quick way to detect for a tier of devices.
// This method detects for all other types of phones,
// but excludes the iPhone and Smartphone Tier devices.
public bool DetectTierOtherPhones()
{
if (DetectMobileLong() == true)
{
//Exclude devices in the other 2 categories
if (DetectTierIphone() ||
DetectTierRichCss())
return false;
else
return true;
}
else
return false;
}
//DetectTierOtherPhones delegate
public delegate void DetectTierOtherPhonesHandler(object page, MDetectArgs args);
public event DetectTierOtherPhonesHandler OnDetectTierOtherPhones;
//***************************************************************
#endregion
//Instead of overriding OnInit(), you can override InitializeCulture()
// so that detection can happen earlier in page's lifecycle, if necessary.
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (useragent == "" && httpaccept == "")
{
useragent = (Request.ServerVariables["HTTP_USER_AGENT"] ?? "").ToUpper();
httpaccept = (Request.ServerVariables["HTTP_ACCEPT"] ?? "").ToUpper();
}
}
}
================================================
FILE: ASP_NET/Sub-Classed Page Technique/MDetect_Test.aspx
================================================
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MDetect_Test.aspx.cs" Inherits="MDetect_Test" %>
================================================
FILE: ASP_NET/Sub-Classed Page Technique/MDetect_Test.aspx.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class MDetect_Test : MDetectPage
{
protected void Page_Load(object sender, EventArgs e)
{
this.FireEvents();
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
//As a test, let's listen for any WebKit-based device.
OnDetectWebkit += new DetectWebkitHandler(MDetect_Test_OnDetectWebkit);
}
void MDetect_Test_OnDetectWebkit(object page, MDetectPage.MDetectArgs args)
{
//Write the Type value from the argument to the web page.
Response.Write("This browser is " + args.Type + "");
}
}
================================================
FILE: ASP_NET/UserControl Technique/MDetectControl.cs
================================================
/* *******************************************
// Copyright 2010-2015, Anthony Hand
//
//
// File version 2015.05.13 (May 13, 2015)
// Updates:
// - Moved MobileESP to GitHub. https://github.com/ahand/mobileesp
// - Opera Mobile/Mini browser has the same UA string on multiple platforms and doesn't differentiate phone vs. tablet.
// - Removed DetectOperaAndroidPhone(). This method is no longer reliable.
// - Removed DetectOperaAndroidTablet(). This method is no longer reliable.
// - Added support for Windows Phone 10: variable and DetectWindowsPhone10()
// - Updated DetectWindowsPhone() to include WP10.
// - Added support for Firefox OS.
// - A variable plus DetectFirefoxOS(), DetectFirefoxOSPhone(), DetectFirefoxOSTablet()
// - NOTE: Firefox doesn't add UA tokens to definitively identify Firefox OS vs. their browsers on other mobile platforms.
// - Added support for Sailfish OS. Not enough info to add a tablet detection method at this time.
// - A variable plus DetectSailfish(), DetectSailfishPhone()
// - Added support for Ubuntu Mobile OS.
// - DetectUbuntu(), DetectUbuntuPhone(), DetectUbuntuTablet()
// - Added support for 2 smart TV OSes. They lack browsers but do have WebViews for use by HTML apps.
// - One variable for Samsung Tizen TVs, plus DetectTizenTV()
// - One variable for LG WebOS TVs, plus DetectWebOSTV()
// - Added DetectTizen(). Tests for “mobile” to disambiguate from Samsung Smart TVs.
// - Removed variables for obsolete devices: deviceHtcFlyer, deviceXoom.
// - Updated DetectAndroid(). No longer has a special test case for the HTC Flyer tablet.
// - Updated DetectAndroidPhone().
// - Updated internal detection code for Android.
// - No longer has a special test case for the HTC Flyer tablet.
// - Checks against DetectOperaMobile() on Android and reports here if relevant.
// - Updated DetectAndroidTablet().
// - No longer has a special test case for the HTC Flyer tablet.
// - Checks against DetectOperaMobile() on Android to exclude it from here.
// - DetectMeego(): Changed definition for this method. Now detects any Meego OS device, not just phones.
// - DetectMeegoPhone(): NEW. For Meego phones. Ought to detect Opera browsers on Meego, as well.
// - DetectTierIphone(): Added support for phones running Sailfish, Ubuntu and Firefox Mobile.
// - DetectTierTablet(): Added support for tablets running Ubuntu and Firefox Mobile.
// - DetectSmartphone(): Added support for Meego phones.
// - Caught this library up to the PHP, JavaScript and Java versions. Updates include:
// - Added support for Bada: a variable and DetectBada(). This detects any Bada OS device, but (almost) all are phones.
// - Refactored the Windows Phone delegate-related properties and features. Now fires for any Windows Phone, not just WP7.
// - The event fires now when DetectWindowsPhone() is true.
// - Added support for Windows Phone 8: DetectWindowsPhone8().
// - Updated DetectWindowsMobile(). Excludes any Windows Phone device, not just WP7.
// - Added support for BlackBerry 10 OS phones: DetectBlackBerry10Phone().
// - Updated DetectSonyMylo().
// - Updated DetectSmartphone() to sync with the other libraries.
// - Updated DetectTierIphone() to sync with the other libraries.
// - OnInit(EventArgs e): Fixed the user agent and httpaccept init logic.
// - Refactored the detection logic in DetectMobileQuick() and DetectMobileLong().
// - Moved a few detection tests for older browsers to Long.
//
//
//
// LICENSE INFORMATION
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific
// language governing permissions and limitations under the License.
//
//
// ABOUT THIS PROJECT
// Project Owner: Anthony Hand
// Email: anthony.hand@gmail.com
// Web Site: http://www.mobileesp.com
// Source Files: https://github.com/ahand/mobileesp
//
// Versions of this code are available for:
// PHP, JavaScript, Java, ASP.NET (C#), and Ruby
//
// *******************************************
*/
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
///
/// Subclass this control to inherit the built-in mobile device detection.
///
public class MDetectControl : System.Web.UI.UserControl
{
private string useragent = "";
private string httpaccept = "";
#region Fields - Detection Argument Values
//standardized values for detection arguments.
private const string dargsIphone = "iphone";
private const string dargsIpod = "ipod";
private const string dargsIpad = "ipad";
private const string dargsIphoneOrIpod = "iphoneoripod";
private const string dargsIos = "ios";
private const string dargsAndroid = "android";
private const string dargsAndroidPhone = "androidphone";
private const string dargsAndroidTablet = "androidtablet";
private const string dargsGoogleTV = "googletv";
private const string dargsWebKit = "webkit";
private const string dargsSymbianOS = "symbianos";
private const string dargsS60 = "series60";
private const string dargsWindowsPhone = "windowsphone";
private const string dargsWindowsMobile = "windowsmobile";
private const string dargsBlackBerry = "blackberry";
private const string dargsBlackBerryWebkit = "blackberrywebkit";
private const string dargsPalmOS = "palmos";
private const string dargsPalmWebOS = "webos";
private const string dargsWebOSTablet = "webostablet";
private const string dargsSmartphone = "smartphone";
private const string dargsBrewDevice = "brew";
private const string dargsDangerHiptop = "dangerhiptop";
private const string dargsOperaMobile = "operamobile";
private const string dargsWapWml = "wapwml";
private const string dargsKindle = "kindle";
private const string dargsMobileQuick = "mobilequick";
private const string dargsTierTablet = "tiertablet";
private const string dargsTierIphone = "tieriphone";
private const string dargsTierRichCss = "tierrichcss";
private const string dargsTierOtherPhones = "tierotherphones";
#endregion Fields - Detection Argument Values
#region Fields - User Agent Keyword Values
private const string engineWebKit = "WEBKIT";
private const string deviceIphone = "IPHONE";
private const string deviceIpod = "IPOD";
private const string deviceIpad = "IPAD";
private const string deviceMacPpc = "MACINTOSH"; //Used for disambiguation
private const string deviceAndroid = "ANDROID";
private const string deviceGoogleTV = "GOOGLETV";
private const string deviceNuvifone = "NUVIFONE"; //Garmin Nuvifone
private const string deviceBada = "BADA"; //Samsung's Bada OS
private const string deviceTizen = "TIZEN"; //Tizen OS
private const string deviceMeego = "MEEGO"; //Meego OS
private const string deviceSailfish = "SAILFISH"; //Sailfish OS
private const string deviceUbuntu = "UBUNTU"; //Ubuntu Mobile OS
private const string deviceSymbian = "SYMBIAN";
private const string deviceS60 = "SERIES60";
private const string deviceS70 = "SERIES70";
private const string deviceS80 = "SERIES80";
private const string deviceS90 = "SERIES90";
private const string deviceWinPhone7 = "WINDOWS PHONE OS 7";
private const string deviceWinPhone8 = "WINDOWS PHONE 8";
private const string deviceWinPhone10 = "WINDOWS PHONE 10";
private const string deviceWinMob = "WINDOWS CE";
private const string deviceWindows = "WINDOWS";
private const string deviceIeMob = "IEMOBILE";
private const string devicePpc = "PPC"; //Stands for PocketPC
private const string enginePie = "WM5 PIE"; //An old Windows Mobile browser
private const string deviceBB = "BLACKBERRY";
private const string deviceBB10 = "BB10"; //For the new BB 10 OS
private const string vndRIM = "VND.RIM"; //Detectable when BB devices emulate IE or Firefox
private const string deviceBBStorm = "BLACKBERRY95"; //Storm 1 and 2
private const string deviceBBBold = "BLACKBERRY97"; //Bold 97x0 (non-touch)
private const string deviceBBBoldTouch = "BLACKBERRY 99"; //Bold 99x0 (touchscreen)
private const string deviceBBTour = "BLACKBERRY96"; //Tour
private const string deviceBBCurve = "BLACKBERRY89"; //Curve2
private const string deviceBBCurveTouch = "BLACKBERRY 938"; //Curve Touch 9380
private const string deviceBBTorch = "BLACKBERRY 98"; //Torch
private const string deviceBBPlaybook = "PLAYBOOK"; //PlayBook tablet
private const string devicePalm = "PALM";
private const string deviceWebOS = "WEBOS"; //For Palm devices
private const string deviceWebOStv = "WEB0S"; //For LG TVs
private const string deviceWebOShp = "HPWOS"; //For HP's line of WebOS devices
private const string engineBlazer = "BLAZER"; //Old Palm
private const string engineXiino = "XIINO"; //Another old Palm
private const string deviceKindle = "KINDLE"; //Amazon Kindle, eInk one
private const string engineSilk = "SILK"; //Amazon's accelerated Silk browser for Kindle Fire
//Initialize private strings for mobile-specific content.
private const string vndwap = "VND.WAP";
private const string wml = "WML";
//Initialize private strings for other random devices and mobile browsers.
private const string deviceTablet = "TABLET"; //Generic term for slate and tablet devices
private const string deviceBrew = "BREW";
private const string deviceDanger = "DANGER";
private const string deviceHiptop = "HIPTOP";
private const string devicePlaystation = "PLAYSTATION";
private const string devicePlaystationVita = "VITA";
private const string deviceNintendoDs = "NITRO";
private const string deviceNintendo = "NINTENDO";
private const string deviceWii = "WII";
private const string deviceXbox = "XBOX";
private const string deviceArchos = "ARCHOS";
private const string engineFirefox = "FIREFOX"; //For Firefox OS
private const string engineOpera = "OPERA"; //Popular browser
private const string engineNetfront = "NETFRONT"; //Common embedded OS browser
private const string engineUpBrowser = "UP.BROWSER"; //common on some phones
private const string engineOpenWeb = "OPENWEB"; //Transcoding by OpenWave server
private const string deviceMidp = "MIDP"; //a mobile Java technology
private const string uplink = "UP.LINK";
private const string engineTelecaQ = "TELECA Q"; //a modern feature phone browser
private const string devicePda = "PDA"; //some devices report themselves as PDAs
private const string mini = "MINI"; //Some mobile browsers put "mini" in their names.
private const string mobile = "MOBILE"; //Some mobile browsers put "mobile" in their user agent private strings.
private const string mobi = "MOBI"; //Some mobile browsers put "mobi" in their user agent private strings.
//Smart TV strings
private const string smartTV1 = "SMART-TV"; //Samsung Tizen smart TVs
private const string smartTV2 = "SMARTTV"; //LG WebOS smart TVs
//Use Maemo, Tablet, and Linux to test for Nokia"s Internet Tablets.
private const string maemo = "MAEMO";
private const string linux = "LINUX";
private const string qtembedded = "QT EMBEDDED"; //for Sony Mylo
private const string mylocom2 = "COM2"; //for Sony Mylo also
//In some UserAgents, the only clue is the manufacturer.
private const string manuSonyEricsson = "SONYERICSSON";
private const string manuericsson = "ERICSSON";
private const string manuSamsung1 = "SEC-SGH";
private const string manuSony = "SONY";
private const string manuHtc = "HTC"; //Popular Android and WinMo manufacturer
//In some UserAgents, the only clue is the operator.
private const string svcDocomo = "DOCOMO";
private const string svcKddi = "KDDI";
private const string svcVodafone = "VODAFONE";
//Disambiguation strings.
private const string disUpdate = "UPDATE"; //pda vs. update
#endregion Fields - User Agent Keyword Values
///
/// To instantiate a WebPage sub-class with built-in
/// mobile device detection delegates and events.
///
public MDetectControl()
{
}
///
/// To run the device detection methods andd fire
/// any existing OnDetectXXX events.
///
public void FireEvents()
{
if (useragent == "" && httpaccept == "")
{
useragent = (Request.ServerVariables["HTTP_USER_AGENT"] ?? "").ToUpper();
httpaccept = (Request.ServerVariables["HTTP_ACCEPT"] ?? "").ToUpper();
}
#region Event Fire Methods
MDetectArgs mda = null;
if (this.DetectIpod())
{
mda = new MDetectArgs(dargsIpod);
if (this.OnDetectIpod != null)
{
this.OnDetectIpod(this, mda);
}
}
if (this.DetectIpad())
{
mda = new MDetectArgs(dargsIpad);
if (this.OnDetectIpad != null)
{
this.OnDetectIpad(this, mda);
}
}
if (this.DetectIphone())
{
mda = new MDetectArgs(dargsIphone);
if (this.OnDetectIphone != null)
{
this.OnDetectIphone(this, mda);
}
}
if (this.DetectIphoneOrIpod())
{
mda = new MDetectArgs(dargsIphoneOrIpod);
if (this.OnDetectDetectIPhoneOrIpod != null)
{
this.OnDetectDetectIPhoneOrIpod(this, mda);
}
}
if (this.DetectIos())
{
mda = new MDetectArgs(dargsIos);
if (this.OnDetectIos != null)
{
this.OnDetectIos(this, mda);
}
}
if (this.DetectAndroid())
{
mda = new MDetectArgs(dargsAndroid);
if (this.OnDetectAndroid != null)
{
this.OnDetectAndroid(this, mda);
}
}
if (this.DetectAndroidPhone())
{
mda = new MDetectArgs(dargsAndroidPhone);
if (this.OnDetectAndroidPhone != null)
{
this.OnDetectAndroidPhone(this, mda);
}
}
if (this.DetectAndroidTablet())
{
mda = new MDetectArgs(dargsAndroidTablet);
if (this.OnDetectAndroidTablet != null)
{
this.OnDetectAndroidTablet(this, mda);
}
}
if (this.DetectGoogleTV())
{
mda = new MDetectArgs(dargsGoogleTV);
if (this.OnDetectGoogleTV != null)
{
this.OnDetectGoogleTV(this, mda);
}
}
if (this.DetectWebkit())
{
mda = new MDetectArgs(dargsWebKit);
if (this.OnDetectWebkit != null)
{
this.OnDetectWebkit(this, mda);
}
}
if (this.DetectS60OssBrowser())
{
mda = new MDetectArgs(dargsS60);
if (this.OnDetectS60OssBrowser != null)
{
this.OnDetectS60OssBrowser(this, mda);
}
}
if (this.DetectSymbianOS())
{
mda = new MDetectArgs(dargsSymbianOS);
if (this.OnDetectSymbianOS != null)
{
this.OnDetectSymbianOS(this, mda);
}
}
if (this.DetectWindowsPhone())
{
mda = new MDetectArgs(dargsWindowsPhone);
if (this.OnDetectWindowsPhone != null)
{
this.OnDetectWindowsPhone(this, mda);
}
}
if (this.DetectWindowsMobile())
{
mda = new MDetectArgs(dargsWindowsMobile);
if (this.OnDetectWindowsMobile != null)
{
this.OnDetectWindowsMobile(this, mda);
}
}
if (this.DetectBlackBerry())
{
mda = new MDetectArgs(dargsBlackBerry);
if (this.OnDetectBlackBerry != null)
{
this.OnDetectBlackBerry(this, mda);
}
}
if (this.DetectBlackBerryWebKit())
{
mda = new MDetectArgs(dargsBlackBerryWebkit);
if (this.OnDetectBlackBerryWebkit != null)
{
this.OnDetectBlackBerryWebkit(this, mda);
}
}
if (this.DetectPalmOS())
{
mda = new MDetectArgs(dargsPalmOS);
if (this.OnDetectPalmOS != null)
{
this.OnDetectPalmOS(this, mda);
}
}
if (this.DetectPalmWebOS())
{
mda = new MDetectArgs(dargsPalmWebOS);
if (this.OnDetectPalmWebOS != null)
{
this.OnDetectPalmWebOS(this, mda);
}
}
if (this.DetectWebOSTablet())
{
mda = new MDetectArgs(dargsWebOSTablet);
if (this.OnDetectWebOSTablet != null)
{
this.OnDetectWebOSTablet(this, mda);
}
}
if (this.DetectSmartphone())
{
mda = new MDetectArgs(dargsSmartphone);
if (this.OnDetectSmartphone != null)
{
this.OnDetectSmartphone(this, mda);
}
}
if (this.DetectBrewDevice())
{
mda = new MDetectArgs(dargsBrewDevice);
if (this.OnDetectBrewDevice != null)
{
this.OnDetectBrewDevice(this, mda);
}
}
if (this.DetectDangerHiptop())
{
mda = new MDetectArgs(dargsDangerHiptop);
if (this.OnDetectDangerHiptop != null)
{
this.OnDetectDangerHiptop(this, mda);
}
}
if (this.DetectOperaMobile())
{
mda = new MDetectArgs(dargsOperaMobile);
if (this.OnDetectOperaMobile != null)
{
this.OnDetectOperaMobile(this, mda);
}
}
if (this.DetectWapWml())
{
mda = new MDetectArgs(dargsWapWml);
if (this.OnDetectWapWml != null)
{
this.OnDetectWapWml(this, mda);
}
}
if (this.DetectKindle())
{
mda = new MDetectArgs(dargsKindle);
if (this.OnDetectKindle != null)
{
this.OnDetectKindle(this, mda);
}
}
if (this.DetectMobileQuick())
{
mda = new MDetectArgs(dargsMobileQuick);
if (this.OnDetectMobileQuick != null)
{
this.OnDetectMobileQuick(this, mda);
}
}
if (this.DetectTierTablet())
{
mda = new MDetectArgs(dargsTierTablet);
if (this.OnDetectTierTablet != null)
{
this.OnDetectTierTablet(this, mda);
}
}
if (this.DetectTierIphone())
{
mda = new MDetectArgs(dargsTierIphone);
if (this.OnDetectTierIphone != null)
{
this.OnDetectTierIphone(this, mda);
}
}
if (this.DetectTierRichCss())
{
mda = new MDetectArgs(dargsTierRichCss);
if (this.OnDetectTierRichCss != null)
{
this.OnDetectTierRichCss(this, mda);
}
}
if (this.DetectTierOtherPhones())
{
mda = new MDetectArgs(dargsTierOtherPhones);
if (this.OnDetectTierOtherPhones != null)
{
this.OnDetectTierOtherPhones(this, mda);
}
}
#endregion Event Fire Methods
}
public class MDetectArgs : EventArgs
{
public MDetectArgs(string type)
{
this.Type = type;
}
public readonly string Type;
}
#region Mobile Device Detection Methods
//*****************************
// Start device detection
//*****************************
//**************************
// Detects if the current device is an iPhone.
public bool DetectIphone()
{
if (useragent.IndexOf(deviceIphone)!= -1)
{
//The iPad and iPod touch say they're an iPhone! So let's disambiguate.
if (DetectIpad() || DetectIpod())
{
return false;
}
else
return true;
}
else
return false;
}
//IPhone delegate
public delegate void DetectIphoneHandler(object page, MDetectArgs args);
public event DetectIphoneHandler OnDetectIphone;
//**************************
// Detects if the current device is an iPod Touch.
public bool DetectIpod()
{
if (useragent.IndexOf(deviceIpod)!= -1)
return true;
else
return false;
}
//Ipod delegate
public delegate void DetectIpodHandler(object page, MDetectArgs args);
public event DetectIpodHandler OnDetectIpod;
//**************************
// Detects if the current device is an iPad tablet.
public bool DetectIpad()
{
if (useragent.IndexOf(deviceIpad) != -1 && DetectWebkit())
return true;
else
return false;
}
//Ipod delegate
public delegate void DetectIpadHandler(object page, MDetectArgs args);
public event DetectIpadHandler OnDetectIpad;
//**************************
// Detects if the current device is an iPhone or iPod Touch.
public bool DetectIphoneOrIpod()
{
//We repeat the searches here because some iPods may report themselves as an iPhone, which would be okay.
if (useragent.IndexOf(deviceIphone)!= -1 ||
useragent.IndexOf(deviceIpod)!= -1)
return true;
else
return false;
}
//IPhoneOrIpod delegate
public delegate void DetectIPhoneOrIpodHandler(object page, MDetectArgs args);
public event DetectIPhoneOrIpodHandler OnDetectDetectIPhoneOrIpod;
//**************************
// Detects *any* iOS device: iPhone, iPod Touch, iPad.
public bool DetectIos()
{
if (DetectIphoneOrIpod() || DetectIpad())
return true;
else
return false;
}
//Ios delegate
public delegate void DetectIosHandler(object page, MDetectArgs args);
public event DetectIosHandler OnDetectIos;
//**************************
// Detects *any* Android OS-based device: phone, tablet, and multi-media player.
// Also detects Google TV.
public bool DetectAndroid()
{
if ((useragent.IndexOf(deviceAndroid) != -1) ||
DetectGoogleTV())
return true;
return false;
}
//Android delegate
public delegate void DetectAndroidHandler(object page, MDetectArgs args);
public event DetectAndroidHandler OnDetectAndroid;
//**************************
// Detects if the current device is a (small-ish) Android OS-based device
// used for calling and/or multi-media (like a Samsung Galaxy Player).
// Google says these devices will have 'Android' AND 'mobile' in user agent.
// Ignores tablets (Honeycomb and later).
public bool DetectAndroidPhone()
{
//First, let's make sure we're on an Android device.
if (!DetectAndroid())
return false;
//If it's Android and has 'mobile' in it, Google says it's a phone.
if (useragent.IndexOf(mobile) != -1)
return true;
//Special check for Android devices with Opera Mobile/Mini. They should report here.
if (DetectOperaMobile())
return true;
return false;
}
//Android Phone delegate
public delegate void DetectAndroidPhoneHandler(object page, MDetectArgs args);
public event DetectAndroidPhoneHandler OnDetectAndroidPhone;
//**************************
// Detects if the current device is a (self-reported) Android tablet.
// Google says these devices will have 'Android' and NOT 'mobile' in their user agent.
public bool DetectAndroidTablet()
{
//First, let's make sure we're on an Android device.
if (!DetectAndroid())
return false;
//Special check for Android devices with Opera Mobile/Mini. They should NOT report here.
if (DetectOperaMobile())
return false;
//Otherwise, if it's Android and does NOT have 'mobile' in it, Google says it's a tablet.
if (useragent.IndexOf(mobile) > -1)
return false;
else
return true;
}
//Android Tablet delegate
public delegate void DetectAndroidTabletHandler(object page, MDetectArgs args);
public event DetectAndroidTabletHandler OnDetectAndroidTablet;
//**************************
// Detects if the current device is a GoogleTV device.
public bool DetectGoogleTV()
{
if (useragent.IndexOf(deviceGoogleTV) != -1)
return true;
else
return false;
}
//GoogleTV delegate
public delegate void DetectGoogleTVHandler(object page, MDetectArgs args);
public event DetectGoogleTVHandler OnDetectGoogleTV;
//**************************
// Detects if the current device is an Android OS-based device and
// the browser is based on WebKit.
public bool DetectAndroidWebKit()
{
if (DetectAndroid() && DetectWebkit())
return true;
else
return false;
}
//**************************
// Detects if the current browser is based on WebKit.
public bool DetectWebkit()
{
if (useragent.IndexOf(engineWebKit)!= -1)
return true;
else
return false;
}
//Webkit delegate
public delegate void DetectWebkitHandler(object page, MDetectArgs args);
public event DetectWebkitHandler OnDetectWebkit;
//**************************
// Detects if the current browser is the Nokia S60 Open Source Browser.
public bool DetectS60OssBrowser()
{
//First, test for WebKit, then make sure it's either Symbian or S60.
if (DetectWebkit())
{
if (useragent.IndexOf(deviceSymbian)!= -1 ||
useragent.IndexOf(deviceS60)!= -1)
{
return true;
}
else
return false;
}
else
return false;
}
//S60OssBrowser delegate
public delegate void DetectS60OssBrowserHandler(object page, MDetectArgs args);
public event DetectS60OssBrowserHandler OnDetectS60OssBrowser;
//**************************
// Detects if the current device is any Symbian OS-based device,
// including older S60, Series 70, Series 80, Series 90, and UIQ,
// or other browsers running on these devices.
public bool DetectSymbianOS()
{
if (useragent.IndexOf(deviceSymbian)!= -1 ||
useragent.IndexOf(deviceS60)!= -1 ||
useragent.IndexOf(deviceS70)!= -1 ||
useragent.IndexOf(deviceS80)!= -1 ||
useragent.IndexOf(deviceS90)!= -1)
return true;
else
return false;
}
//SymbianOS delegate
public delegate void DetectSymbianOSHandler(object page, MDetectArgs args);
public event DetectSymbianOSHandler OnDetectSymbianOS;
//**************************
// Detects if the current browser is a
// Windows Phone 7, 8, or 10 device.
public bool DetectWindowsPhone()
{
if (DetectWindowsPhone7() ||
DetectWindowsPhone8() ||
DetectWindowsPhone10())
return true;
return false;
}
//WindowsPhone delegate
public delegate void DetectWindowsPhoneHandler(object page, MDetectArgs args);
public event DetectWindowsPhoneHandler OnDetectWindowsPhone;
//**************************
// Detects if the current browser is a
// Windows Phone 7 device.
public bool DetectWindowsPhone7()
{
if (useragent.IndexOf(deviceWinPhone7) != -1)
return true;
else
return false;
}
//**************************
// Detects if the current browser is a
// Windows Phone 8 device.
public bool DetectWindowsPhone8()
{
if (useragent.IndexOf(deviceWinPhone8) != -1)
return true;
else
return false;
}
//**************************
// Detects if the current browser is a
// Windows Phone 10 device.
public bool DetectWindowsPhone10()
{
if (useragent.IndexOf(deviceWinPhone10) != -1)
return true;
else
return false;
}
//**************************
// Detects if the current browser is a Windows Mobile device.
// Excludes Windows Phone devices.
// Focuses on Windows Mobile 6.xx and earlier.
public bool DetectWindowsMobile()
{
//Exclude new Windows Phone.
if (DetectWindowsPhone())
return false;
//Most devices use 'Windows CE', but some report 'iemobile'
// and some older ones report as 'PIE' for Pocket IE.
if (useragent.IndexOf(deviceWinMob)!= -1 ||
useragent.IndexOf(deviceIeMob)!= -1 ||
useragent.IndexOf(enginePie) != -1)
return true;
//Test for Windows Mobile PPC but not old Macintosh PowerPC.
if (useragent.IndexOf(devicePpc) != -1 &&
!(useragent.IndexOf(deviceMacPpc) != -1))
return true;
//Test for certain Windwos Mobile-based HTC devices.
if (useragent.IndexOf(manuHtc) != -1 &&
useragent.IndexOf(deviceWindows) != -1)
return true;
if (DetectWapWml() == true &&
useragent.IndexOf(deviceWindows)!= -1)
return true;
else
return false;
}
//WindowsMobile delegate
public delegate void DetectWindowsMobileHandler(object page, MDetectArgs args);
public event DetectWindowsMobileHandler OnDetectWindowsMobile;
//**************************
// Detects if the current browser is any BlackBerry device.
// Includes the PlayBook.
public bool DetectBlackBerry()
{
if (useragent.IndexOf(deviceBB)!= -1)
return true;
if (httpaccept.IndexOf(vndRIM)!= -1)
return true;
else
return false;
}
//BlackBerry delegate
public delegate void DetectBlackBerryHandler(object page, MDetectArgs args);
public event DetectBlackBerryHandler OnDetectBlackBerry;
//**************************
// Detects if the current browser is a BlackBerry 10 OS phone.
// Excludes tablets.
public bool DetectBlackBerry10Phone()
{
if (useragent.IndexOf(deviceBB10) != -1 &&
useragent.IndexOf(mobile) != -1)
return true;
else
return false;
}
//**************************
// Detects if the current browser is on a BlackBerry tablet device.
// Example: PlayBook
public bool DetectBlackBerryTablet()
{
if (useragent.IndexOf(deviceBBPlaybook) != -1)
return true;
else
return false;
}
//**************************
// Detects if the current browser is a BlackBerry device AND uses a
// WebKit-based browser. These are signatures for the new BlackBerry OS 6.
// Examples: Torch. Includes the Playbook.
public bool DetectBlackBerryWebKit()
{
if (DetectBlackBerry() && DetectWebkit())
return true;
else
return false;
}
//BlackBerry Webkit delegate
public delegate void DetectBlackBerryWebkitHandler(object page, MDetectArgs args);
public event DetectBlackBerryWebkitHandler OnDetectBlackBerryWebkit;
//**************************
// Detects if the current browser is a BlackBerry Touch
// device, such as the Storm, Torch, and Bold Touch. Excludes the Playbook.
public bool DetectBlackBerryTouch()
{
if (DetectBlackBerry() &&
(useragent.IndexOf(deviceBBStorm) != -1 ||
useragent.IndexOf(deviceBBTorch) != -1 ||
useragent.IndexOf(deviceBBBoldTouch) != -1 ||
useragent.IndexOf(deviceBBCurveTouch) != -1))
return true;
else
return false;
}
//**************************
// Detects if the current browser is a BlackBerry device AND
// has a more capable recent browser. Excludes the Playbook.
// Excludes the new BlackBerry OS 6 and 7 browser!!
public bool DetectBlackBerryHigh()
{
//Disambiguate for BlackBerry OS 6 or 7 (WebKit) browser
if (DetectBlackBerryWebKit())
return false;
if (DetectBlackBerry())
{
if (DetectBlackBerryTouch() ||
useragent.IndexOf(deviceBBBold) != -1 ||
useragent.IndexOf(deviceBBTour) != -1 ||
useragent.IndexOf(deviceBBCurve) != -1)
return true;
else
return false;
}
else
return false;
}
//**************************
// Detects if the current browser is a BlackBerry device AND
// has an older, less capable browser.
// Examples: Pearl, 8800, Curve1.
public bool DetectBlackBerryLow()
{
if (DetectBlackBerry())
{
//Assume that if it's not in the High tier, then it's Low.
if (DetectBlackBerryHigh() || DetectBlackBerryWebKit())
return false;
else
return true;
}
else
return false;
}
//**************************
// Detects if the current browser is on a PalmOS device.
public bool DetectPalmOS()
{
//Most devices nowadays report as 'Palm', but some older ones reported as Blazer or Xiino.
if (useragent.IndexOf(devicePalm) != -1 ||
useragent.IndexOf(engineBlazer) != -1 ||
useragent.IndexOf(engineXiino) != -1)
{
//Make sure it's not WebOS first
if (DetectPalmWebOS() == true)
return false;
else
return true;
}
else
return false;
}
//PalmOS delegate
public delegate void DetectPalmOSHandler(object page, MDetectArgs args);
public event DetectPalmOSHandler OnDetectPalmOS;
//**************************
// Detects if the current browser is on a Palm device
// running the new WebOS.
public bool DetectPalmWebOS()
{
if (useragent.IndexOf(deviceWebOS) != -1)
return true;
else
return false;
}
//PalmWebOS delegate
public delegate void DetectPalmWebOSHandler(object page, MDetectArgs args);
public event DetectPalmWebOSHandler OnDetectPalmWebOS;
//**************************
// Detects if the current browser is on an HP tablet running WebOS.
public bool DetectWebOSTablet()
{
if (useragent.IndexOf(deviceWebOShp) != -1 &&
useragent.IndexOf(deviceTablet) != -1)
{
return true;
}
else
return false;
}
//WebOS tablet delegate
public delegate void DetectWebOSTabletHandler(object page, MDetectArgs args);
public event DetectWebOSTabletHandler OnDetectWebOSTablet;
//**************************
// Detects if the current browser is on a WebOS smart TV.
public bool DetectWebOSTV()
{
if (useragent.IndexOf(deviceWebOStv) != -1 &&
useragent.IndexOf(smartTV2) != -1)
{
return true;
}
else
return false;
}
//**************************
// Detects if the current browser is Opera Mobile or Mini.
public bool DetectOperaMobile()
{
if (useragent.IndexOf(engineOpera)!= -1)
{
if ((useragent.IndexOf(mini)!= -1) ||
(useragent.IndexOf(mobi)!= -1))
{
return true;
}
else
return false;
}
else
return false;
}
//Opera Mobile delegate
public delegate void DetectOperaMobileHandler(object page, MDetectArgs args);
public event DetectOperaMobileHandler OnDetectOperaMobile;
//**************************
// Detects if the current browser is a
// Garmin Nuvifone.
public bool DetectGarminNuvifone()
{
if (useragent.IndexOf(deviceNuvifone) != -1)
return true;
else
return false;
}
//**************************
// Detects a device running the Bada OS from Samsung.
public bool DetectBada()
{
if (useragent.IndexOf(deviceBada) != -1)
{
return true;
}
else
return false;
}
//**************************
// Detects a device running the Tizen smartphone OS.
public bool DetectTizen()
{
if (useragent.IndexOf(deviceTizen) != -1 &&
useragent.IndexOf(mobile) != -1)
{
return true;
}
else
return false;
}
//**************************
// Detects if the current browser is on a Tizen smart TV.
public bool DetectTizenTV()
{
if (useragent.IndexOf(deviceTizen) != -1 &&
useragent.IndexOf(smartTV1) != -1)
{
return true;
}
else
return false;
}
//**************************
// Detects a device running the Meego OS.
public bool DetectMeego()
{
if (useragent.IndexOf(deviceMeego) != -1)
{
return true;
}
else
return false;
}
//**************************
// Detects a phone running the Meego OS.
public bool DetectMeegoPhone()
{
if (useragent.IndexOf(deviceMeego) != -1 &&
useragent.IndexOf(mobile) != -1)
{
return true;
}
else
return false;
}
//**************************
// Detects a mobile device (probably) running the Firefox OS.
public bool DetectFirefoxOS()
{
if (DetectFirefoxOSPhone() || DetectFirefoxOSTablet())
return true;
return false;
}
//**************************
// Detects a phone (probably) running the Firefox OS.
public bool DetectFirefoxOSPhone()
{
//First, let's make sure we're NOT on another major mobile OS.
if (DetectIos() ||
DetectAndroid() ||
DetectSailfish())
return false;
if ((useragent.IndexOf(engineFirefox) != -1) &&
(useragent.IndexOf(mobile) != -1))
return true;
return false;
}
//**************************
// Detects a tablet (probably) running the Firefox OS.
public bool DetectFirefoxOSTablet()
{
//First, let's make sure we're NOT on another major mobile OS.
if (DetectIos() ||
DetectAndroid() ||
DetectSailfish())
return false;
if ((useragent.IndexOf(engineFirefox) != -1) &&
(useragent.IndexOf(deviceTablet) != -1))
return true;
return false;
}
//**************************
// Detects a device running the Sailfish OS.
public bool DetectSailfish()
{
if (useragent.IndexOf(deviceSailfish) != -1)
return true;
else
return false;
}
//**************************
// Detects a phone running the Sailfish OS.
public bool DetectSailfishPhone()
{
if (DetectSailfish() &&
(useragent.IndexOf(mobile) != -1))
return true;
return false;
}
//**************************
// Detects a mobile device running the Ubuntu Mobile OS.
public bool DetectUbuntu()
{
if (DetectUbuntuPhone() || DetectUbuntuTablet())
return true;
return false;
}
//**************************
// Detects a phone running the Ubuntu Mobile OS.
public bool DetectUbuntuPhone()
{
if ((useragent.IndexOf(deviceUbuntu) != -1) &&
(useragent.IndexOf(mobile) != -1))
return true;
return false;
}
//**************************
// Detects a tablet running the Ubuntu Mobile OS.
public bool DetectUbuntuTablet()
{
if ((useragent.IndexOf(deviceUbuntu) != -1) &&
(useragent.IndexOf(deviceTablet) != -1))
return true;
return false;
}
//**************************
// Detects whether the device is a Brew-powered device.
public bool DetectBrewDevice()
{
if (useragent.IndexOf(deviceBrew)!= -1)
return true;
else
return false;
}
//BrewDevice delegate
public delegate void DetectBrewDeviceHandler(object page, MDetectArgs args);
public event DetectBrewDeviceHandler OnDetectBrewDevice;
//**************************
// Detects the Danger Hiptop device.
public bool DetectDangerHiptop()
{
if (useragent.IndexOf(deviceDanger)!= -1 ||
useragent.IndexOf(deviceHiptop)!= -1)
return true;
else
return false;
}
//DangerHiptop delegate
public delegate void DetectDangerHiptopHandler(object page, MDetectArgs args);
public event DetectDangerHiptopHandler OnDetectDangerHiptop;
//**************************
// Detects whether the device supports WAP or WML.
public bool DetectWapWml()
{
if (httpaccept.IndexOf(vndwap)!= -1 ||
httpaccept.IndexOf(wml)!= -1)
return true;
else
return false;
}
//WapWml delegate
public delegate void DetectWapWmlHandler(object page, MDetectArgs args);
public event DetectWapWmlHandler OnDetectWapWml;
//**************************
// Detects if the current device is an Amazon Kindle (eInk devices only).
// Note: For the Kindle Fire, use the normal Android methods.
public bool DetectKindle()
{
if (useragent.IndexOf(deviceKindle) != -1 &&
!DetectAndroid())
return true;
else
return false;
}
//Kindle delegate
public delegate void DetectKindleHandler(object page, MDetectArgs args);
public event DetectKindleHandler OnDetectKindle;
//**************************
// Detects if the current Amazon device is using the Silk Browser.
// Note: Typically used by the the Kindle Fire.
public bool DetectAmazonSilk()
{
if (useragent.IndexOf(engineSilk) != -1)
return true;
else
return false;
}
//**************************
// Detects if the current device is a Sony Playstation.
public bool DetectSonyPlaystation()
{
if (useragent.IndexOf(devicePlaystation)!= -1)
return true;
else
return false;
}
//**************************
// Detects if the current device is a handheld gaming device with
// a touchscreen and modern iPhone-class browser. Includes the Playstation Vita.
public bool DetectGamingHandheld()
{
if (useragent.IndexOf(devicePlaystation)!= -1 &&
useragent.IndexOf(devicePlaystationVita)!= -1)
return true;
else
return false;
}
//**************************
// Detects if the current device is a Nintendo game device.
public bool DetectNintendo()
{
if (useragent.IndexOf(deviceNintendo)!= -1 ||
useragent.IndexOf(deviceWii)!= -1 ||
useragent.IndexOf(deviceNintendoDs)!= -1)
return true;
else
return false;
}
//**************************
// Detects if the current device is a Microsoft Xbox.
public bool DetectXbox()
{
if (useragent.IndexOf(deviceXbox)!= -1)
return true;
else
return false;
}
//**************************
// Detects if the current device is an Internet-capable game console.
public bool DetectGameConsole()
{
if (DetectSonyPlaystation())
return true;
else if (DetectNintendo())
return true;
else if (DetectXbox())
return true;
else
return false;
}
//**************************
// Detects if the current device supports MIDP, a mobile Java technology.
public bool DetectMidpCapable()
{
if (useragent.IndexOf(deviceMidp)!= -1 ||
httpaccept.IndexOf(deviceMidp)!= -1)
return true;
else
return false;
}
//**************************
// Detects if the current device is on one of the Maemo-based Nokia Internet Tablets.
public bool DetectMaemoTablet()
{
if (useragent.IndexOf(maemo) != -1)
return true;
//For Nokia N810, must be Linux + Tablet, or else it could be something else.
else if (useragent.IndexOf(linux) != -1 &&
useragent.IndexOf(deviceTablet) != -1 &&
!DetectWebOSTablet() &&
!DetectAndroid())
return true;
else
return false;
}
//**************************
// Detects if the current device is an Archos media player/Internet tablet.
public bool DetectArchos()
{
if (useragent.IndexOf(deviceArchos)!= -1)
return true;
else
return false;
}
//**************************
// Detects if the current browser is a Sony Mylo device.
public bool DetectSonyMylo()
{
if ((useragent.IndexOf(manuSony)!= -1) &&
((useragent.IndexOf(qtembedded)!= -1) ||
(useragent.IndexOf(mylocom2)!= -1)))
return true;
return false;
}
//*****************************
// Device Classes
//*****************************
//**************************
// Check to see whether the device is any device
// in the 'smartphone' category.
// Note: It's better to use DetectTierIphone() for modern touchscreen devices.
public bool DetectSmartphone()
{
if (DetectTierIphone() ||
DetectS60OssBrowser() ||
DetectSymbianOS() ||
DetectWindowsMobile() ||
DetectBlackBerry() ||
DetectMeegoPhone() ||
DetectPalmOS())
return true;
else
return false;
}
//DetectSmartphone delegate
public delegate void DetectSmartphoneHandler(object page, MDetectArgs args);
public event DetectSmartphoneHandler OnDetectSmartphone;
//**************************
// Detects if the current device is a mobile device.
// This method catches most of the popular modern devices.
// Excludes Apple iPads and other modern tablets.
public bool DetectMobileQuick()
{
//Let's exclude tablets
if (DetectTierTablet())
return false;
//Most mobile browsing is done on smartphones
if (DetectSmartphone())
return true;
//Catch-all for many mobile devices
if (useragent.IndexOf(mobile) != -1)
return true;
if (DetectOperaMobile())
return true;
//We also look for Kindle devices
if (DetectKindle() ||
DetectAmazonSilk())
return true;
if (DetectWapWml() ||
DetectMidpCapable() ||
DetectBrewDevice())
return true;
if ((useragent.IndexOf(engineNetfront) != -1) ||
(useragent.IndexOf(engineUpBrowser) != -1))
return true;
return false;
}
//DetectMobileQuick delegate
public delegate void DetectMobileQuickHandler(object page, MDetectArgs args);
public event DetectMobileQuickHandler OnDetectMobileQuick;
//**************************
// The longer and more thorough way to detect for a mobile device.
// Will probably detect most feature phones,
// smartphone-class devices, Internet Tablets,
// Internet-enabled game consoles, etc.
// This ought to catch a lot of the more obscure and older devices, also --
// but no promises on thoroughness!
public bool DetectMobileLong()
{
if (DetectMobileQuick())
return true;
if (DetectGameConsole())
return true;
if (DetectDangerHiptop() ||
DetectMaemoTablet() ||
DetectSonyMylo() ||
DetectArchos())
return true;
if ((useragent.IndexOf(devicePda) != -1) &&
(useragent.IndexOf(disUpdate) != -1))
return true;
//Detect older phones from certain manufacturers and operators.
if ((useragent.IndexOf(uplink) != -1) ||
(useragent.IndexOf(engineOpenWeb) != -1) ||
(useragent.IndexOf(manuSamsung1) != -1) ||
(useragent.IndexOf(manuSonyEricsson) != -1) ||
(useragent.IndexOf(manuericsson) != -1) ||
(useragent.IndexOf(svcDocomo) != -1) ||
(useragent.IndexOf(svcKddi) != -1) ||
(useragent.IndexOf(svcVodafone) != -1))
return true;
return false;
}
//*****************************
// For Mobile Web Site Design
//*****************************
//**************************
// The quick way to detect for a tier of devices.
// This method detects for the new generation of
// HTML 5 capable, larger screen tablets.
// Includes iPad, Android (e.g., Xoom), BB Playbook, WebOS, etc.
public bool DetectTierTablet()
{
if (DetectIpad()
|| DetectAndroidTablet()
|| DetectBlackBerryTablet()
|| DetectFirefoxOSTablet()
|| DetectUbuntuTablet()
|| DetectWebOSTablet())
return true;
else
return false;
}
//DetectTierTablet delegate
public delegate void DetectTierTabletHandler(object page, MDetectArgs args);
public event DetectTierTabletHandler OnDetectTierTablet;
//**************************
// The quick way to detect for a tier of devices.
// This method detects for devices which can
// display iPhone-optimized web content.
// Includes iPhone, iPod Touch, Android, Windows Phone, BB10, Playstation Vita, etc.
public bool DetectTierIphone()
{
if (DetectIphoneOrIpod() ||
DetectAndroidPhone() ||
DetectWindowsPhone() ||
DetectBlackBerry10Phone() ||
DetectPalmWebOS() ||
DetectBada() ||
DetectTizen() ||
DetectFirefoxOSPhone() ||
DetectSailfishPhone() ||
DetectUbuntuPhone() ||
DetectGamingHandheld())
return true;
else
return false;
}
//DetectTierIphone delegate
public delegate void DetectTierIphoneHandler(object page, MDetectArgs args);
public event DetectTierIphoneHandler OnDetectTierIphone;
//**************************
// The quick way to detect for a tier of devices.
// This method detects for devices which are likely to be capable
// of viewing CSS content optimized for the iPhone,
// but may not necessarily support JavaScript.
// Excludes all iPhone Tier devices.
public bool DetectTierRichCss()
{
if (DetectMobileQuick())
{
//Exclude iPhone Tier and e-Ink Kindle devices
if (DetectTierIphone() || DetectKindle())
return false;
if (DetectWebkit() ||
DetectS60OssBrowser())
return true;
//Note: 'High' BlackBerry devices ONLY
if (DetectBlackBerryHigh() == true)
return true;
//Older Windows 'Mobile' isn't good enough for iPhone Tier.
if (DetectWindowsMobile() == true)
return true;
if (useragent.IndexOf(engineTelecaQ) != -1)
return true;
else
return false;
}
else
return false;
}
//DetectTierRichCss delegate
public delegate void DetectTierRichCssHandler(object page, MDetectArgs args);
public event DetectTierRichCssHandler OnDetectTierRichCss;
//**************************
// The quick way to detect for a tier of devices.
// This method detects for all other types of phones,
// but excludes the iPhone and Smartphone Tier devices.
public bool DetectTierOtherPhones()
{
if (DetectMobileLong() == true)
{
//Exclude devices in the other 2 categories
if (DetectTierIphone() ||
DetectTierRichCss())
return false;
else
return true;
}
else
return false;
}
//DetectTierOtherPhones delegate
public delegate void DetectTierOtherPhonesHandler(object page, MDetectArgs args);
public event DetectTierOtherPhonesHandler OnDetectTierOtherPhones;
//***************************************************************
#endregion
//Instead of overriding OnInit(), you can override InitializeCulture()
// so that detection can happen earlier in page's lifecycle, if necessary.
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (useragent == "" && httpaccept == "")
{
useragent = (Request.ServerVariables["HTTP_USER_AGENT"] ?? "").ToUpper();
httpaccept = (Request.ServerVariables["HTTP_ACCEPT"] ?? "").ToUpper();
}
}
}
================================================
FILE: ASP_NET/UserControl Technique/MobileDetectControl.ascx
================================================
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MobileDetectControl.ascx.cs" Inherits="WebApplication1.MobileDetect.MobileDetectControl" %>
================================================
FILE: ASP_NET/UserControl Technique/MobileDetectControl.ascx.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1.MobileDetect
{
public partial class MobileDetectControl : MDetectControl
{
protected void Page_Load(object sender, EventArgs e)
{
this.FireEvents();
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
//As a test, let's listen for any WebKit-based device.
OnDetectWebkit += new DetectWebkitHandler(MobileDetectControl_OnDetectWebkit);
}
void MobileDetectControl_OnDetectWebkit(object page, MDetectControl.MDetectArgs args)
{
//Write the Type value from the argument to the web page.
Response.Write("This browser is " + args.Type + "");
}
}
}
================================================
FILE: ASP_NET/UserControl Technique/MobileDetectControl.ascx.designer.cs
================================================
//------------------------------------------------------------------------------
//
// This code was generated by a tool.
// Runtime Version:2.0.50727.42
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
//------------------------------------------------------------------------------
namespace WebApplication1.MobileDetect
{
public partial class MobileDetectControl
{
}
}
================================================
FILE: ASP_NET/UserControl Technique/MobileDetectTestPage.aspx
================================================
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MobileDetectTestPage.aspx.cs" Inherits="WebApplication1.MobileDetect.MobileDetectTestPage" %>
<%@ Register TagPrefix="mdc" TagName="MobileDetect" Src="MobileDetectControl.ascx" %>
================================================
FILE: ASP_NET/UserControl Technique/MobileDetectTestPage.aspx.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1.MobileDetect
{
public partial class MobileDetectTestPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
================================================
FILE: ASP_NET/UserControl Technique/MobileDetectTestPage.aspx.designer.cs
================================================
//------------------------------------------------------------------------------
//
// This code was generated by a tool.
// Runtime Version:2.0.50727.3607
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
//------------------------------------------------------------------------------
namespace WebApplication1.MobileDetect {
public partial class MobileDetectTestPage {
///
/// form1 control.
///
///
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
///
protected global::System.Web.UI.HtmlControls.HtmlForm form1;
///
/// MDC control.
///
///
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
///
protected global::WebApplication1.MobileDetect.MobileDetectControl MDC;
}
}
================================================
FILE: Cpp/mdetect.h
================================================
/* *******************************************
// Copyright 2010-2015, Anthony Hand
//
//
// File version 2015.05.13 (May 13, 2015)
// Updates:
// - Moved MobileESP to GitHub. https://github.com/ahand/mobileesp
// - Opera Mobile/Mini browser has the same UA string on multiple platforms and doesn't differentiate phone vs. tablet.
// - Removed DetectOperaAndroidPhone(). This method is no longer reliable.
// - Removed DetectOperaAndroidTablet(). This method is no longer reliable.
// - Added support for Windows Phone 10: variable and DetectWindowsPhone10()
// - Updated DetectWindowsPhone() to include WP10.
// - Added support for Firefox OS.
// - A variable plus DetectFirefoxOS(), DetectFirefoxOSPhone(), DetectFirefoxOSTablet()
// - NOTE: Firefox doesn't add UA tokens to definitively identify Firefox OS vs. their browsers on other mobile platforms.
// - Added support for Sailfish OS. Not enough info to add a tablet detection method at this time.
// - A variable plus DetectSailfish(), DetectSailfishPhone()
// - Added support for Ubuntu Mobile OS.
// - DetectUbuntu(), DetectUbuntuPhone(), DetectUbuntuTablet()
// - Added support for 2 smart TV OSes. They lack browsers but do have WebViews for use by HTML apps.
// - One variable for Samsung Tizen TVs, plus DetectTizenTV()
// - One variable for LG WebOS TVs, plus DetectWebOSTV()
// - Updated DetectTizen(). Now tests for “mobile” to disambiguate from Samsung Smart TVs
// - Removed variables for obsolete devices: deviceHtcFlyer, deviceXoom.
// - Updated DetectAndroid(). No longer has a special test case for the HTC Flyer tablet.
// - Updated DetectAndroidPhone().
// - Updated internal detection code for Android.
// - No longer has a special test case for the HTC Flyer tablet.
// - Checks against DetectOperaMobile() on Android and reports here if relevant.
// - Updated DetectAndroidTablet().
// - No longer has a special test case for the HTC Flyer tablet.
// - Checks against DetectOperaMobile() on Android to exclude it from here.
// - DetectMeego(): Changed definition for this method. Now detects any Meego OS device, not just phones.
// - DetectMeegoPhone(): NEW. For Meego phones. Ought to detect Opera browsers on Meego, as well.
// - DetectTierIphone(): Added support for phones running Sailfish, Ubuntu and Firefox Mobile.
// - DetectTierTablet(): Added support for tablets running Ubuntu and Firefox Mobile.
// - DetectSmartphone(): Added support for Meego phones.
// - Removed the variable for Obigo, an embedded browser. The browser is on old devices.
// - Couldn’t find info on current Obigo embedded browser user agent strings.
// - Refactored the detection logic in DetectMobileQuick() and DetectMobileLong().
// - Moved a few detection tests for older browsers to Long.
//
//
//
// File version 2014.01.24 (January 24, 2014)
// Updates:
// - Ported to C++ by Kiran T. Based on the PHP library.
//
//
//
// LICENSE INFORMATION
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific
// language governing permissions and limitations under the License.
//
//
// ABOUT THIS PROJECT
// Project Owner: Anthony Hand
// Email: anthony.hand@gmail.com
// Web Site: http://www.mobileesp.com
// Source Files: https://github.com/ahand/mobileesp
//
// Versions of this code are available for:
// PHP, JavaScript, Java, ASP.NET (C#), C++, and Ruby
//
// *******************************************
*/
#ifndef MDETECT_H
#define MDETECT_H
#include
#include
using namespace std;
namespace MobileESP
{
//Initialize some initial smartphone string variables.
const string engineWebKit = "webkit";
const string deviceIphone = "iphone";
const string deviceIpod = "ipod";
const string deviceIpad = "ipad";
const string deviceMacPpc = "macintosh"; //Used for disambiguation
const string deviceAndroid = "android";
const string deviceGoogleTV = "googletv";
const string deviceHtcFlyer = "htc_flyer"; //HTC Flyer
const string deviceWinPhone7 = "windows phone os 7";
const string deviceWinPhone8 = "windows phone 8";
const string deviceWinPhone10 = "windows phone 10";
const string deviceWinMob = "windows ce";
const string deviceWindows = "windows";
const string deviceIeMob = "iemobile";
const string devicePpc = "ppc"; //Stands for PocketPC
const string enginePie = "wm5 pie"; //An old Windows Mobile
const string deviceBB = "blackberry";
const string deviceBB10 = "bb10"; //For the new BB 10 OS
const string vndRIM = "vnd.rim"; //Detectable when BB devices emulate IE or Firefox
const string deviceBBStorm = "blackberry95"; //Storm 1 and 2
const string deviceBBBold = "blackberry97"; //Bold 97x0 (non-touch)
const string deviceBBBoldTouch = "blackberry 99"; //Bold 99x0 (touchscreen)
const string deviceBBTour = "blackberry96"; //Tour
const string deviceBBCurve = "blackberry89"; //Curve2
const string deviceBBCurveTouch = "blackberry 938"; //Curve Touch
const string deviceBBTorch = "blackberry 98"; //Torch
const string deviceBBPlaybook = "playbook"; //PlayBook tablet
const string deviceSymbian = "symbian";
const string deviceS60 = "series60";
const string deviceS70 = "series70";
const string deviceS80 = "series80";
const string deviceS90 = "series90";
const string devicePalm = "palm";
const string deviceWebOS = "webos"; //For Palm devices
const string deviceWebOStv = "web0s"; //For LG TVs
const string deviceWebOShp = "hpwos"; //For HP's line of WebOS devices
const string engineBlazer = "blazer"; //Old Palm browser
const string engineXiino = "xiino"; //Another old Palm
const string deviceNuvifone = "nuvifone"; //Garmin Nuvifone
const string deviceBada = "bada"; //Samsung's Bada OS
const string deviceTizen = "tizen"; //Tizen OS
const string deviceMeego = "meego"; //Meego OS
const string deviceSailfish = "sailfish"; //Sailfish OS
const string deviceUbuntu = "ubuntu"; //Ubuntu Mobile OS
const string deviceKindle = "kindle"; //Amazon Kindle, eInk one
const string engineSilk = "silk-accelerated"; //Amazon's accelerated Silk browser for Kindle Fire
//Initialize variables for mobile-specific content.
const string vndwap = "vnd.wap";
const string wml = "wml";
//Initialize variables for other random devices and mobile browsers.
const string deviceTablet = "tablet"; //Generic term for slate and tablet devices
const string deviceBrew = "brew";
const string deviceDanger = "danger";
const string deviceHiptop = "hiptop";
const string devicePlaystation = "playstation";
const string devicePlaystationVita = "vita";
const string deviceNintendoDs = "nitro";
const string deviceNintendo = "nintendo";
const string deviceWii = "wii";
const string deviceXbox = "xbox";
const string deviceArchos = "archos";
const string engineFirefox = "firefox"; //For Firefox OS
const string engineOpera = "opera"; //Popular browser
const string engineNetfront = "netfront"; //Common embedded OS browser
const string engineUpBrowser = "up.browser"; //common on some phones
const string engineOpenWeb = "openweb"; //Transcoding by OpenWave server
const string deviceMidp = "midp"; //a mobile Java technology
const string uplink = "up.link";
const string engineTelecaQ = "teleca q"; //a modern feature phone browser
const string devicePda = "pda"; //some devices report themselves as PDAs
const string mini = "mini"; //Some mobile browsers put 'mini' in their names.
const string mobile = "mobile"; //Some mobile browsers put 'mobile' in their user agent strings.
const string mobi = "mobi"; //Some mobile browsers put 'mobi' in their user agent strings.
//Smart TV strings
const string smartTV1 = "smart-tv"; //Samsung Tizen smart TVs
const string smartTV2 = "smarttv"; //LG WebOS smart TVs
//Use Maemo, Tablet, and Linux to test for Nokia's Internet Tablets.
const string maemo = "maemo";
const string llinux = "linux";
const string qtembedded = "qt embedded"; //for Sony Mylo and others
const string mylocom2 = "com2"; //for Sony Mylo also
//In some UserAgents, the only clue is the manufacturer.
const string manuSonyEricsson = "sonyericsson";
const string manuericsson = "ericsson";
const string manuSamsung1 = "sec-sgh";
const string manuSony = "sony";
const string manuHtc = "htc";
//In some UserAgents, the only clue is the operator.
const string svcDocomo = "docomo";
const string svcKddi = "kddi";
const string svcVodafone = "vodafone";
//Disambiguation strings.
const string disUpdate = "update"; //pda vs. update
//**************************
// The uagent_info class encapsulates information about
// a browser's connection to your web site.
// You can use it to find out whether the browser asking for
// your site's content is probably running on a mobile device.
// The methods were written so you can be as granular as you want.
// For example, enquiring whether it's as specific as an iPod Touch or
// as general as a smartphone class device.
// The object's methods return 1 for true, or 0 for false.
class uagent_info
{
private:
string useragent;
string httpaccept;
//Let's store values for quickly accessing the same info multiple times. InitCompleted
bool initCompleted; //Stores whether we're currently initializing the most popular functions.
bool isWebkit; //Stores the result of DetectWebkit()
bool isMobilePhone; //Stores the result of DetectMobileQuick()
bool isIphone; //Stores the result of DetectIphone()
bool isAndroid; //Stores the result of DetectAndroid()
bool isAndroidPhone; //Stores the result of DetectAndroidPhone()
bool isTierTablet; //Stores the result of DetectTierTablet()
bool isTierIphone; //Stores the result of DetectTierIphone()
bool isTierRichCss; //Stores the result of DetectTierRichCss()
bool isTierGenericMobile; //Stores the result of DetectTierOtherPhones()
//**************************
// Initialize Key Stored Values.
void InitDeviceScan()
{
//Save these properties to speed processing
isWebkit = DetectWebkit();
isIphone = DetectIphone();
isAndroid = DetectAndroid();
isAndroidPhone = DetectAndroidPhone();
//These tiers are the most useful for web development
isTierTablet = DetectTierTablet(); //Do first
isTierIphone = DetectTierIphone(); //Do second
isMobilePhone = DetectMobileQuick(); //Do third
//Optional: Comment these out if you NEVER use them.
isTierRichCss = DetectTierRichCss();
isTierGenericMobile = DetectTierOtherPhones();
initCompleted = true;
}
public:
//**************************
//The constructor.
uagent_info(const string &user_agent,const string &accept):
useragent(user_agent),
httpaccept(accept),
initCompleted(false),
isWebkit(false),
isMobilePhone(false),
isIphone(false),
isAndroid(false),
isAndroidPhone(false),
isTierTablet(false),
isTierIphone(false),
isTierRichCss(false),
isTierGenericMobile(false)
{
std::transform(useragent.begin(), useragent.end(),useragent.begin(), ::tolower);
std::transform(httpaccept.begin(), httpaccept.end(),httpaccept.begin(), ::tolower);
//Let's initialize some values to save cycles later.
InitDeviceScan();
}
//**************************
//Returns the contents of the User Agent value, in lower case.
string Get_Uagent()
{
return useragent;
}
//**************************
//Returns the contents of the HTTP Accept value, in lower case.
string Get_HttpAccept()
{
return httpaccept;
}
//**************************
// Detects if the current device is an iPhone.
bool DetectIphone()
{
if (initCompleted == true ||
isIphone == true)
return isIphone;
if (useragent.find( MobileESP::deviceIphone) != std::string::npos)
{
//The iPad and iPod Touch say they're an iPhone. So let's disambiguate.
if (DetectIpad() == true ||
DetectIpod() == true)
return false;
//Yay! It's an iPhone!
else
return true;
}
else
return false;
}
//**************************
// Detects if the current device is an iPod Touch.
bool DetectIpod()
{
if (useragent.find( MobileESP::deviceIpod) != std::string::npos)
return true;
else
return false;
}
//**************************
// Detects if the current device is an iPad tablet.
bool DetectIpad()
{
if (useragent.find( MobileESP::deviceIpad) != std::string::npos &&
DetectWebkit() == true)
return true;
else
return false;
}
//**************************
// Detects if the current device is an iPhone or iPod Touch.
bool DetectIphoneOrIpod()
{
//We repeat the searches here because some iPods may report themselves as an iPhone, which would be okay.
if (DetectIphone() == true ||
DetectIpod() == true)
return true;
else
return false;
}
//**************************
// Detects *any* iOS device: iPhone, iPod Touch, iPad.
bool DetectIos()
{
if ((DetectIphoneOrIpod() == true) ||
(DetectIpad() == true))
return true;
else
return false;
}
//**************************
// Detects *any* Android OS-based device: phone, tablet, and multi-media player.
// Also detects Google TV.
bool DetectAndroid()
{
if (initCompleted == true ||
isAndroid == true)
return isAndroid;
if ((useragent.find( MobileESP::deviceAndroid) != std::string::npos)
|| (DetectGoogleTV() == true))
return true;
return false;
}
//**************************
// Detects if the current device is a (small-ish) Android OS-based device
// used for calling and/or multi-media (like a Samsung Galaxy Player).
// Google says these devices will have 'Android' AND 'mobile' in user agent.
// Ignores tablets (Honeycomb and later).
bool DetectAndroidPhone()
{
if (initCompleted == true ||
isAndroidPhone == true)
return isAndroidPhone;
//First, let's make sure we're on an Android device.
if (DetectAndroid() == false)
return false;
//If it's Android and has 'mobile' in it, Google says it's a phone.
if (useragent.find( MobileESP::mobile) != std::string::npos)
return true;
//Special check for Android devices with Opera Mobile/Mini. They should report here.
if ((DetectOperaMobile() == true))
return true;
return false;
}
//**************************
// Detects if the current device is a (self-reported) Android tablet.
// Google says these devices will have 'Android' and NOT 'mobile' in their user agent.
bool DetectAndroidTablet()
{
//First, let's make sure we're on an Android device.
if (DetectAndroid() == false)
return false;
//Special check for Android devices with Opera Mobile/Mini. They should NOT report here.
if (DetectOperaMobile() == true)
return false;
//Otherwise, if it's Android and does NOT have 'mobile' in it, Google says it's a tablet.
if (useragent.find( MobileESP::mobile) != std::string::npos)
return false;
return true;
}
//**************************
// Detects if the current device is an Android OS-based device and
// the browser is based on WebKit.
bool DetectAndroidWebKit()
{
if ((DetectAndroid() == true) &&
(DetectWebkit() == true))
return true;
else
return false;
}
//**************************
// Detects if the current device is a GoogleTV.
bool DetectGoogleTV()
{
if (useragent.find( MobileESP::deviceGoogleTV) != std::string::npos)
return true;
else
return false;
}
//**************************
// Detects if the current browser is based on WebKit.
bool DetectWebkit()
{
if (initCompleted == true ||
isWebkit == true)
return isWebkit;
if (useragent.find( MobileESP::engineWebKit) != std::string::npos)
return true;
else
return false;
}
//**************************
// Detects if the current browser is a
// Windows Phone 7, 8, or 10 device.
bool DetectWindowsPhone()
{
if ((DetectWindowsPhone7() == true)
|| (DetectWindowsPhone8() == true)
|| (DetectWindowsPhone10() == true))
return true;
else
return false;
}
//**************************
// Detects a Windows Phone 7 device (in mobile browsing mode).
bool DetectWindowsPhone7()
{
if (useragent.find( MobileESP::deviceWinPhone7) != std::string::npos)
return true;
else
return false;
}
//**************************
// Detects a Windows Phone 8 device (in mobile browsing mode).
bool DetectWindowsPhone8()
{
if (useragent.find( MobileESP::deviceWinPhone8) != std::string::npos)
return true;
else
return false;
}
//**************************
// Detects a Windows Phone 10 device (in mobile browsing mode).
bool DetectWindowsPhone10()
{
if (useragent.find( MobileESP::deviceWinPhone10) != std::string::npos)
return true;
else
return false;
}
//**************************
// Detects if the current browser is a Windows Mobile device.
// Excludes Windows Phone 7 and later devices.
// Focuses on Windows Mobile 6.xx and earlier.
bool DetectWindowsMobile()
{
if (DetectWindowsPhone() == true)
return false;
//Most devices use 'Windows CE', but some report 'iemobile'
// and some older ones report as 'PIE' for Pocket IE.
if (useragent.find( MobileESP::deviceWinMob) != std::string::npos ||
useragent.find( MobileESP::deviceIeMob) != std::string::npos ||
useragent.find( MobileESP::enginePie) != std::string::npos)
return true;
//Test for Windows Mobile PPC but not old Macintosh PowerPC.
if (useragent.find( MobileESP::devicePpc) != std::string::npos
&& !(useragent.find( MobileESP::deviceMacPpc) > 1))
return true;
//Test for certain Windwos Mobile-based HTC devices.
if (useragent.find( MobileESP::manuHtc) != std::string::npos &&
useragent.find( MobileESP::deviceWindows) != std::string::npos)
return true;
if (DetectWapWml() == true &&
useragent.find( MobileESP::deviceWindows) != std::string::npos)
return true;
else
return false;
}
//**************************
// Detects if the current browser is any BlackBerry device.
// Includes BB10 OS, but excludes the PlayBook.
bool DetectBlackBerry()
{
if ((useragent.find( MobileESP::deviceBB) != std::string::npos) ||
(httpaccept.find( MobileESP::vndRIM) != std::string::npos))
return true;
if (DetectBlackBerry10Phone() == true)
return true;
else
return false;
}
//**************************
// Detects if the current browser is a BlackBerry 10 OS phone.
// Excludes tablets.
bool DetectBlackBerry10Phone()
{
if ((useragent.find( MobileESP::deviceBB10) != std::string::npos) &&
(useragent.find( MobileESP::mobile) != std::string::npos))
return true;
else
return false;
}
//**************************
// Detects if the current browser is on a BlackBerry tablet device.
// Examples: PlayBook
bool DetectBlackBerryTablet()
{
if ((useragent.find( MobileESP::deviceBBPlaybook) != std::string::npos))
return true;
else
return false;
}
//**************************
// Detects if the current browser is a BlackBerry phone device AND uses a
// WebKit-based browser. These are signatures for the new BlackBerry OS 6.
// Examples: Torch. Includes the Playbook.
bool DetectBlackBerryWebKit()
{
if ((DetectBlackBerry() == true) &&
(DetectWebkit() == true))
return true;
else
return false;
}
//**************************
// Detects if the current browser is a BlackBerry Touch phone device with
// a large screen, such as the Storm, Torch, and Bold Touch. Excludes the Playbook.
bool DetectBlackBerryTouch()
{
if ((useragent.find( MobileESP::deviceBBStorm) != std::string::npos) ||
(useragent.find( MobileESP::deviceBBTorch) != std::string::npos) ||
(useragent.find( MobileESP::deviceBBBoldTouch) != std::string::npos) ||
(useragent.find( MobileESP::deviceBBCurveTouch) != std::string::npos))
return true;
else
return false;
}
//**************************
// Detects if the current browser is a BlackBerry OS 5 device AND
// has a more capable recent browser. Excludes the Playbook.
// Examples, Storm, Bold, Tour, Curve2
// Excludes the new BlackBerry OS 6 and 7 browser!!
bool DetectBlackBerryHigh()
{
//Disambiguate for BlackBerry OS 6 or 7 (WebKit) browser
if (DetectBlackBerryWebKit() == true)
return false;
if (DetectBlackBerry() == true)
{
if ((DetectBlackBerryTouch() == true) ||
useragent.find( MobileESP::deviceBBBold) != std::string::npos ||
useragent.find( MobileESP::deviceBBTour) != std::string::npos ||
useragent.find( MobileESP::deviceBBCurve) != std::string::npos)
{
return true;
}
else
return false;
}
else
return false;
}
//**************************
// Detects if the current browser is a BlackBerry device AND
// has an older, less capable browser.
// Examples: Pearl, 8800, Curve1.
bool DetectBlackBerryLow()
{
if (DetectBlackBerry() == true)
{
//Assume that if it's not in the High tier, then it's Low.
if ((DetectBlackBerryHigh() == true) ||
(DetectBlackBerryWebKit() == true))
return false;
else
return true;
}
else
return false;
}
//**************************
// Detects if the current browser is the Nokia S60 Open Source Browser.
bool DetectS60OssBrowser()
{
//First, test for WebKit, then make sure it's either Symbian or S60.
if (DetectWebkit() == true)
{
if (useragent.find( MobileESP::deviceSymbian) != std::string::npos ||
useragent.find( MobileESP::deviceS60) != std::string::npos)
{
return true;
}
else
return false;
}
else
return false;
}
//**************************
// Detects if the current device is any Symbian OS-based device,
// including older S60, Series 70, Series 80, Series 90, and UIQ,
// or other browsers running on these devices.
bool DetectSymbianOS()
{
if (useragent.find( MobileESP::deviceSymbian) != std::string::npos ||
useragent.find( MobileESP::deviceS60) != std::string::npos ||
useragent.find( MobileESP::deviceS70) != std::string::npos ||
useragent.find( MobileESP::deviceS80) != std::string::npos ||
useragent.find( MobileESP::deviceS90) != std::string::npos)
return true;
else
return false;
}
//**************************
// Detects if the current browser is on a PalmOS device.
bool DetectPalmOS()
{
//Make sure it's not WebOS first
if (DetectPalmWebOS() == true)
return false;
//Most devices nowadays report as 'Palm', but some older ones reported as Blazer or Xiino.
if (useragent.find( MobileESP::devicePalm) != std::string::npos ||
useragent.find( MobileESP::engineBlazer) != std::string::npos ||
useragent.find( MobileESP::engineXiino) != std::string::npos)
return true;
else
return false;
}
//**************************
// Detects if the current browser is on a Palm device
// running the new WebOS.
bool DetectPalmWebOS()
{
if (useragent.find( MobileESP::deviceWebOS) != std::string::npos)
return true;
else
return false;
}
//**************************
// Detects if the current browser is on an HP tablet running WebOS.
bool DetectWebOSTablet()
{
if ((useragent.find( MobileESP::deviceWebOShp) != std::string::npos)
&& (useragent.find( MobileESP::deviceTablet) != std::string::npos))
return true;
else
return false;
}
//**************************
// Detects if the current browser is on a WebOS smart TV.
bool DetectWebOSTV()
{
if ((useragent.find( MobileESP::deviceWebOStv) != std::string::npos)
&& (useragent.find( MobileESP::smartTV2) != std::string::npos))
return true;
else
return false;
}
//**************************
// Detects if the current browser is Opera Mobile or Mini.
bool DetectOperaMobile()
{
if (useragent.find( MobileESP::engineOpera) != std::string::npos)
{
if ((useragent.find( MobileESP::mini) != std::string::npos) ||
(useragent.find( MobileESP::mobi) != std::string::npos))
return true;
else
return false;
}
else
return false;
}
//**************************
// Detects if the current device is an Amazon Kindle (eInk devices only).
// Note: For the Kindle Fire, use the normal Android methods.
bool DetectKindle()
{
if (useragent.find( MobileESP::deviceKindle) != std::string::npos &&
DetectAndroid() == false)
return true;
else
return false;
}
//**************************
// Detects if the current Amazon device has turned on the Silk accelerated browsing feature.
// Note: Typically used by the the Kindle Fire.
bool DetectAmazonSilk()
{
if (useragent.find( MobileESP::engineSilk) != std::string::npos)
return true;
else
return false;
}
//**************************
// Detects if a Garmin Nuvifone device.
bool DetectGarminNuvifone()
{
if (useragent.find( MobileESP::deviceNuvifone) != std::string::npos)
return true;
else
return false;
}
//**************************
// Detects a device running the Bada smartphone OS from Samsung.
bool DetectBada()
{
if (useragent.find( MobileESP::deviceBada) != std::string::npos)
return true;
else
return false;
}
//**************************
// Detects a device running the Tizen smartphone OS.
bool DetectTizen()
{
if ((useragent.find( MobileESP::deviceTizen) != std::string::npos)
&& (useragent.find( MobileESP::mobile) != std::string::npos))
return true;
else
return false;
}
//**************************
// Detects if the current browser is on a Tizen smart TV.
bool DetectTizenTV()
{
if ((useragent.find( MobileESP::deviceTizen) != std::string::npos)
&& (useragent.find( MobileESP::smartTV1) != std::string::npos))
return true;
else
return false;
}
//**************************
// Detects a device running the Meego OS.
bool DetectMeego()
{
if (useragent.find( MobileESP::deviceMeego) != std::string::npos)
return true;
else
return false;
}
//**************************
// Detects a phone running the Meego OS.
bool DetectMeegoPhone()
{
if ((useragent.find( MobileESP::deviceMeego) != std::string::npos)
&& (useragent.find( MobileESP::mobi) != std::string::npos))
return true;
else
return false;
}
//**************************
// Detects a mobile device (probably) running the Firefox OS.
bool DetectFirefoxOS()
{
if ((DetectFirefoxOSPhone() == true) || DetectFirefoxOSTablet())
return true;
return false;
}
//**************************
// Detects a phone (probably) running the Firefox OS.
bool DetectFirefoxOSPhone()
{
//First, let's make sure we're NOT on another major mobile OS.
if (DetectIos() ||
DetectAndroid() ||
DetectSailfish())
return false;
if ((useragent.find( MobileESP::engineFirefox) != std::string::npos) &&
(useragent.find( MobileESP::mobile) != std::string::npos))
return true;
return false;
}
//**************************
// Detects a tablet (probably) running the Firefox OS.
bool DetectFirefoxOSTablet()
{
//First, let's make sure we're NOT on another major mobile OS.
if (DetectIos() ||
DetectAndroid() ||
DetectSailfish())
return false;
if ((useragent.find( MobileESP::engineFirefox) != std::string::npos) &&
(useragent.find( MobileESP::deviceTablet) != std::string::npos))
return true;
return false;
}
//**************************
// Detects a device running the Sailfish OS.
bool DetectSailfish()
{
if (useragent.find( MobileESP::deviceSailfish) != std::string::npos)
return true;
else
return false;
}
//**************************
// Detects a phone running the Sailfish OS.
bool DetectSailfishPhone()
{
if ((DetectSailfish() == true) &&
(useragent.find( MobileESP::mobile) != std::string::npos))
return true;
return false;
}
//**************************
// Detects a mobile device running the Ubuntu Mobile OS.
bool DetectUbuntu()
{
if ((DetectUbuntuPhone() == true) || DetectUbuntuTablet() == true)
return true;
return false;
}
//**************************
// Detects a phone running the Ubuntu Mobile OS.
bool DetectUbuntuPhone()
{
if ((useragent.find( MobileESP::deviceUbuntu) != std::string::npos) &&
(useragent.find( MobileESP::mobile) != std::string::npos))
return true;
return false;
}
//**************************
// Detects a tablet running the Ubuntu Mobile OS.
bool DetectUbuntuTablet()
{
if ((useragent.find( MobileESP::deviceUbuntu) != std::string::npos) &&
(useragent.find( MobileESP::deviceTablet) != std::string::npos))
return true;
return false;
}
//**************************
// Detects the Danger Hiptop device.
bool DetectDangerHiptop()
{
if (useragent.find( MobileESP::deviceDanger) != std::string::npos ||
useragent.find( MobileESP::deviceHiptop) != std::string::npos)
return true;
else
return false;
}
//**************************
// Detects if the current browser is a Sony Mylo device.
bool DetectSonyMylo()
{
if ((useragent.find( MobileESP::manuSony) != std::string::npos) &&
((useragent.find( MobileESP::qtembedded) != std::string::npos) ||
(useragent.find( MobileESP::mylocom2) != std::string::npos)))
return true;
else
return false;
}
//**************************
// Detects if the current device is on one of the Maemo-based Nokia Internet Tablets.
bool DetectMaemoTablet()
{
if (useragent.find( MobileESP::maemo) != std::string::npos)
return true;
//For Nokia N810, must be Linux + Tablet, or else it could be something else.
if ((useragent.find( MobileESP::llinux) != std::string::npos)
&& (useragent.find( MobileESP::deviceTablet) != std::string::npos)
&& (DetectWebOSTablet() == false)
&& (DetectAndroid() == false))
return true;
else
return false;
}
//**************************
// Detects if the current device is an Archos media player/Internet tablet.
bool DetectArchos()
{
if (useragent.find( MobileESP::deviceArchos) != std::string::npos)
return true;
else
return false;
}
//**************************
// Detects if the current device is an Internet-capable game console.
// Includes many handheld consoles.
bool DetectGameConsole()
{
if ((DetectSonyPlaystation() == true) ||
(DetectNintendo() == true) ||
(DetectXbox() == true))
return true;
else
return false;
}
//**************************
// Detects if the current device is a Sony Playstation.
bool DetectSonyPlaystation()
{
if (useragent.find( MobileESP::devicePlaystation) != std::string::npos)
return true;
else
return false;
}
//**************************
// Detects if the current device is a handheld gaming device with
// a touchscreen and modern iPhone-class browser. Includes the Playstation Vita.
bool DetectGamingHandheld()
{
if ((useragent.find( MobileESP::devicePlaystation) != std::string::npos) &&
(useragent.find( MobileESP::devicePlaystationVita) != std::string::npos))
return true;
else
return false;
}
//**************************
// Detects if the current device is a Nintendo game device.
bool DetectNintendo()
{
if (useragent.find( MobileESP::deviceNintendo) != std::string::npos ||
useragent.find( MobileESP::deviceWii) != std::string::npos ||
useragent.find( MobileESP::deviceNintendoDs) != std::string::npos)
return true;
else
return false;
}
//**************************
// Detects if the current device is a Microsoft Xbox.
bool DetectXbox()
{
if (useragent.find( MobileESP::deviceXbox) != std::string::npos)
return true;
else
return false;
}
//**************************
// Detects whether the device is a Brew-powered device.
bool DetectBrewDevice()
{
if (useragent.find( MobileESP::deviceBrew) != std::string::npos)
return true;
else
return false;
}
//**************************
// Detects whether the device supports WAP or WML.
bool DetectWapWml()
{
if (httpaccept.find( MobileESP::vndwap) != std::string::npos ||
httpaccept.find( MobileESP::wml) != std::string::npos)
return true;
else
return false;
}
//**************************
// Detects if the current device supports MIDP, a mobile Java technology.
bool DetectMidpCapable()
{
if (useragent.find( MobileESP::deviceMidp) != std::string::npos ||
httpaccept.find( MobileESP::deviceMidp) != std::string::npos)
return true;
else
return false;
}
//*****************************
// Device Classes
//*****************************
//**************************
// Check to see whether the device is *any* 'smartphone'.
// Note: It's better to use DetectTierIphone() for modern touchscreen devices.
bool DetectSmartphone()
{
//Exclude duplicates from TierIphone
if ((DetectTierIphone() == true)
|| (DetectS60OssBrowser() == true)
|| (DetectSymbianOS() == true)
|| (DetectWindowsMobile() == true)
|| (DetectBlackBerry() == true)
|| (DetectMeegoPhone() == true)
|| (DetectPalmWebOS() == true))
return true;
else
return false;
}
//**************************
// The quick way to detect for a mobile device.
// Will probably detect most recent/current mid-tier Feature Phones
// as well as smartphone-class devices. Excludes Apple iPads and other modern tablets.
bool DetectMobileQuick()
{
if (initCompleted == true ||
isMobilePhone == true)
return isMobilePhone;
//Let's exclude tablets
if (isTierTablet == true)
return false;
//Most mobile browsing is done on smartphones
if (DetectSmartphone() == true)
return true;
//Catch-all for many mobile devices
if (useragent.find( MobileESP::mobile) != std::string::npos)
return true;
if (DetectOperaMobile() == true)
return true;
//We also look for Kindle devices
if (DetectKindle() == true ||
DetectAmazonSilk() == true)
return true;
if ((DetectWapWml() == true)
|| (DetectMidpCapable() == true)
|| (DetectBrewDevice() == true))
return true;
if ((useragent.find( MobileESP::engineNetfront) != std::string::npos)
|| (useragent.find( MobileESP::engineUpBrowser) != std::string::npos))
return true;
else
return false;
}
//**************************
// The longer and more thorough way to detect for a mobile device.
// Will probably detect most feature phones,
// smartphone-class devices, Internet Tablets,
// Internet-enabled game consoles, etc.
// This ought to catch a lot of the more obscure and older devices, also --
// but no promises on thoroughness!
bool DetectMobileLong()
{
if (DetectMobileQuick() == true)
return true;
if (DetectGameConsole() == true)
return true;
if ((DetectDangerHiptop() == true)
|| (DetectMaemoTablet() == true)
|| (DetectSonyMylo() == true)
|| (DetectArchos() == true))
return true;
if ((useragent.find( MobileESP::devicePda) != std::string::npos) &&
!(useragent.find( MobileESP::disUpdate) != std::string::npos))
return true;
//Detect older phones from certain manufacturers and operators.
if ((useragent.find( MobileESP::uplink) != std::string::npos)
|| (useragent.find( MobileESP::engineOpenWeb) != std::string::npos)
|| (useragent.find( MobileESP::manuSamsung1) != std::string::npos)
|| (useragent.find( MobileESP::manuSonyEricsson) != std::string::npos)
|| (useragent.find( MobileESP::manuericsson) != std::string::npos)
|| (useragent.find( MobileESP::svcDocomo) != std::string::npos)
|| (useragent.find( MobileESP::svcKddi) != std::string::npos)
|| (useragent.find( MobileESP::svcVodafone) != std::string::npos))
return true;
return false;
}
//*****************************
// For Mobile Web Site Design
//*****************************
//**************************
// The quick way to detect for a tier of devices.
// This method detects for the new generation of
// HTML 5 capable, larger screen tablets.
// Includes iPad, Android (e.g., Xoom), BB Playbook, WebOS, etc.
bool DetectTierTablet()
{
if (initCompleted == true ||
isTierTablet == true)
return isTierTablet;
if ((DetectIpad() == true)
|| (DetectAndroidTablet() == true)
|| (DetectBlackBerryTablet() == true)
|| (DetectFirefoxOSTablet() == true)
|| (DetectUbuntuTablet() == true)
|| (DetectWebOSTablet() == true))
return true;
else
return false;
}
//**************************
// The quick way to detect for a tier of devices.
// This method detects for devices which can
// display iPhone-optimized web content.
// Includes iPhone, iPod Touch, Android, Windows Phone 7 and 8, BB10, WebOS, Playstation Vita, etc.
bool DetectTierIphone()
{
if (initCompleted == true ||
isTierIphone == true)
return isTierIphone;
if ((DetectIphoneOrIpod() == true)
|| (DetectAndroidPhone() == true)
|| (DetectWindowsPhone() == true)
|| (DetectBlackBerry10Phone() == true)
|| (DetectPalmWebOS() == true)
|| (DetectBada() == true)
|| (DetectTizen() == true)
|| (DetectFirefoxOSPhone() == true)
|| (DetectSailfishPhone() == true)
|| (DetectUbuntuPhone() == true)
|| (DetectGamingHandheld() == true))
return true;
//Note: BB10 phone is in the previous paragraph
if ((DetectBlackBerryWebKit() == true) &&
(DetectBlackBerryTouch() == true))
return true;
else
return false;
}
//**************************
// The quick way to detect for a tier of devices.
// This method detects for devices which are likely to be capable
// of viewing CSS content optimized for the iPhone,
// but may not necessarily support JavaScript.
// Excludes all iPhone Tier devices.
bool DetectTierRichCss()
{
if (initCompleted == true ||
isTierRichCss == true)
return isTierRichCss;
if (DetectMobileQuick() == true)
{
//Exclude iPhone Tier and e-Ink Kindle devices
if ((DetectTierIphone() == true) ||
(DetectKindle() == true))
return false;
//The following devices are explicitly ok.
if (DetectWebkit() == true) //Any WebKit
return true;
if (DetectS60OssBrowser() == true)
return true;
//Note: 'High' BlackBerry devices ONLY
if (DetectBlackBerryHigh() == true)
return true;
//Older Windows 'Mobile' isn't good enough for iPhone Tier.
if (DetectWindowsMobile() == true)
return true;
if (useragent.find( MobileESP::engineTelecaQ) != std::string::npos)
return true;
//default
else
return false;
}
else
return false;
}
//**************************
// The quick way to detect for a tier of devices.
// This method detects for all other types of phones,
// but excludes the iPhone and RichCSS Tier devices.
bool DetectTierOtherPhones()
{
if (initCompleted == true ||
isTierGenericMobile == true)
return isTierGenericMobile;
//Exclude devices in the other 2 categories
if ((DetectMobileLong() == true)
&& (DetectTierIphone() == false)
&& (DetectTierRichCss() == false))
return true;
else
return false;
}
};
}
/* Example code *
#include
#include "mdetect.h"
int main(int argc, char** argv)
{
int ret = 0;
if(argc < 3) {
std::cout << "Usage is mdetect [user agent string] [Accept string]" << std::endl;
} else {
MobileESP::uagent_info usageInfo(argv[1],argv[2]);
if(true == usageInfo.DetectMobileQuick()) {
std::cout << "Passed in user agent is from a mobile browser" << std::endl;
} else {
std::cout << "Passed in user agent is *NOT* from a mobile browser" << std::endl;
}
}
return ret;
}
*/
#endif //MDETECT_H
================================================
FILE: Java/UAgentInfo.java
================================================
/* *******************************************
// Copyright 2010-2015, Anthony Hand
//
//
// File version 2015.05.13 (May 13, 2015)
// Updates:
// - Moved MobileESP to GitHub. https://github.com/ahand/mobileesp
// - Opera Mobile/Mini browser has the same UA string on multiple platforms and doesn't differentiate phone vs. tablet.
// - Removed DetectOperaAndroidPhone(). This method is no longer reliable.
// - Removed DetectOperaAndroidTablet(). This method is no longer reliable.
// - Added support for Windows Phone 10: variable and DetectWindowsPhone10()
// - Updated DetectWindowsPhone() to include WP10.
// - Added support for Firefox OS.
// - A variable plus DetectFirefoxOS(), DetectFirefoxOSPhone(), DetectFirefoxOSTablet()
// - NOTE: Firefox doesn't add UA tokens to definitively identify Firefox OS vs. their browsers on other mobile platforms.
// - Added support for Sailfish OS. Not enough info to add a tablet detection method at this time.
// - A variable plus DetectSailfish(), DetectSailfishPhone()
// - Added support for Ubuntu Mobile OS.
// - DetectUbuntu(), DetectUbuntuPhone(), DetectUbuntuTablet()
// - Added support for 2 smart TV OSes. They lack browsers but do have WebViews for use by HTML apps.
// - One variable for Samsung Tizen TVs, plus DetectTizenTV()
// - One variable for LG WebOS TVs, plus DetectWebOSTV()
// - Updated DetectTizen(). Now tests for "mobile" to disambiguate from Samsung Smart TVs
// - Removed variables for obsolete devices: deviceHtcFlyer, deviceXoom.
// - Updated DetectAndroid(). No longer has a special test case for the HTC Flyer tablet.
// - Updated DetectAndroidPhone().
// - Updated internal detection code for Android.
// - No longer has a special test case for the HTC Flyer tablet.
// - Checks against DetectOperaMobile() on Android and reports here if relevant.
// - Updated DetectAndroidTablet().
// - No longer has a special test case for the HTC Flyer tablet.
// - Checks against DetectOperaMobile() on Android to exclude it from here.
// - DetectMeego(): Changed definition for this method. Now detects any Meego OS device, not just phones.
// - DetectMeegoPhone(): NEW. For Meego phones. Ought to detect Opera browsers on Meego, as well.
// - DetectTierIphone(): Added support for phones running Sailfish, Ubuntu and Firefox Mobile.
// - DetectTierTablet(): Added support for tablets running Ubuntu and Firefox Mobile.
// - DetectSmartphone(): Added support for Meego phones.
// - Refactored the detection logic in DetectMobileQuick() and DetectMobileLong().
// - Moved a few detection tests for older browsers to Long.
//
//
//
// LICENSE INFORMATION
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific
// language governing permissions and limitations under the License.
//
//
// ABOUT THIS PROJECT
// Project Owner: Anthony Hand
// Email: anthony.hand@gmail.com
// Web Site: http://www.mobileesp.com
// Source Files: https://github.com/ahand/mobileesp
//
// Versions of this code are available for:
// PHP, JavaScript, Java, ASP.NET (C#), and Ruby
//
// *******************************************
*/
package com.handinteractive.mobile;
/**
* The DetectSmartPhone class encapsulates information about
* a browser's connection to your web site.
* You can use it to find out whether the browser asking for
* your site's content is probably running on a mobile device.
* The methods were written so you can be as granular as you want.
* For example, enquiring whether it's as specific as an iPod Touch or
* as general as a smartphone class device.
* The object's methods return true, or false.
*/
public class UAgentInfo {
// User-Agent and Accept HTTP request headers
private String userAgent = "";
private String httpAccept = "";
// Let's store values for quickly accessing the same info multiple times.
public boolean initCompleted = false;
public boolean isWebkit = false; //Stores the result of DetectWebkit()
public boolean isMobilePhone = false; //Stores the result of DetectMobileQuick()
public boolean isIphone = false; //Stores the result of DetectIphone()
public boolean isAndroid = false; //Stores the result of DetectAndroid()
public boolean isAndroidPhone = false; //Stores the result of DetectAndroidPhone()
public boolean isTierTablet = false; //Stores the result of DetectTierTablet()
public boolean isTierIphone = false; //Stores the result of DetectTierIphone()
public boolean isTierRichCss = false; //Stores the result of DetectTierRichCss()
public boolean isTierGenericMobile = false; //Stores the result of DetectTierOtherPhones()
// Initialize some initial smartphone string variables.
public static final String engineWebKit = "webkit";
public static final String deviceIphone = "iphone";
public static final String deviceIpod = "ipod";
public static final String deviceIpad = "ipad";
public static final String deviceMacPpc = "macintosh"; //Used for disambiguation
public static final String deviceAndroid = "android";
public static final String deviceGoogleTV = "googletv";
public static final String deviceWinPhone7 = "windows phone os 7";
public static final String deviceWinPhone8 = "windows phone 8";
public static final String deviceWinPhone10 = "windows phone 10";
public static final String deviceWinMob = "windows ce";
public static final String deviceWindows = "windows";
public static final String deviceIeMob = "iemobile";
public static final String devicePpc = "ppc"; //Stands for PocketPC
public static final String enginePie = "wm5 pie"; //An old Windows Mobile
public static final String deviceBB = "blackberry";
public static final String deviceBB10 = "bb10"; //For the new BB 10 OS
public static final String vndRIM = "vnd.rim"; //Detectable when BB devices emulate IE or Firefox
public static final String deviceBBStorm = "blackberry95"; //Storm 1 and 2
public static final String deviceBBBold = "blackberry97"; //Bold 97x0 (non-touch)
public static final String deviceBBBoldTouch = "blackberry 99"; //Bold 99x0 (touchscreen)
public static final String deviceBBTour = "blackberry96"; //Tour
public static final String deviceBBCurve = "blackberry89"; //Curve 2
public static final String deviceBBCurveTouch = "blackberry 938"; //Curve Touch 9380
public static final String deviceBBTorch = "blackberry 98"; //Torch
public static final String deviceBBPlaybook = "playbook"; //PlayBook tablet
public static final String deviceSymbian = "symbian";
public static final String deviceS60 = "series60";
public static final String deviceS70 = "series70";
public static final String deviceS80 = "series80";
public static final String deviceS90 = "series90";
public static final String devicePalm = "palm";
public static final String deviceWebOS = "webos"; //For Palm devices
public static final String deviceWebOStv = "web0s"; //For LG TVs
public static final String deviceWebOShp = "hpwos"; //For HP's line of WebOS devices
public static final String deviceNuvifone = "nuvifone"; //Garmin Nuvifone
public static final String deviceBada = "bada"; //Samsung's Bada OS
public static final String deviceTizen = "tizen"; //Tizen OS
public static final String deviceMeego = "meego"; //Meego OS
public static final String deviceSailfish = "sailfish"; //Sailfish OS
public static final String deviceUbuntu = "ubuntu"; //Ubuntu Mobile OS
public static final String deviceKindle = "kindle"; //Amazon Kindle, eInk one
public static final String engineSilk = "silk-accelerated"; //Amazon's accelerated Silk browser for Kindle Fire
public static final String engineBlazer = "blazer"; //Old Palm
public static final String engineXiino = "xiino"; //Another old Palm
//Initialize variables for mobile-specific content.
public static final String vndwap = "vnd.wap";
public static final String wml = "wml";
//Initialize variables for other random devices and mobile browsers.
public static final String deviceTablet = "tablet"; //Generic term for slate and tablet devices
public static final String deviceBrew = "brew";
public static final String deviceDanger = "danger";
public static final String deviceHiptop = "hiptop";
public static final String devicePlaystation = "playstation";
public static final String devicePlaystationVita = "vita";
public static final String deviceNintendoDs = "nitro";
public static final String deviceNintendo = "nintendo";
public static final String deviceWii = "wii";
public static final String deviceXbox = "xbox";
public static final String deviceArchos = "archos";
public static final String engineFirefox = "firefox"; //For Firefox OS
public static final String engineOpera = "opera"; //Popular browser
public static final String engineNetfront = "netfront"; //Common embedded OS browser
public static final String engineUpBrowser = "up.browser"; //common on some phones
public static final String engineOpenWeb = "openweb"; //Transcoding by OpenWave server
public static final String deviceMidp = "midp"; //a mobile Java technology
public static final String uplink = "up.link";
public static final String engineTelecaQ = "teleca q"; //a modern feature phone browser
public static final String devicePda = "pda"; //some devices report themselves as PDAs
public static final String mini = "mini"; //Some mobile browsers put "mini" in their names.
public static final String mobile = "mobile"; //Some mobile browsers put "mobile" in their user agent strings.
public static final String mobi = "mobi"; //Some mobile browsers put "mobi" in their user agent strings.
//Smart TV strings
public static final String smartTV1 = "smart-tv"; //Samsung Tizen smart TVs
public static final String smartTV2 = "smarttv"; //LG WebOS smart TVs
//Use Maemo, Tablet, and Linux to test for Nokia"s Internet Tablets.
public static final String maemo = "maemo";
public static final String linux = "linux";
public static final String qtembedded = "qt embedded"; //for Sony Mylo
public static final String mylocom2 = "com2"; //for Sony Mylo also
//In some UserAgents, the only clue is the manufacturer.
public static final String manuSonyEricsson = "sonyericsson";
public static final String manuericsson = "ericsson";
public static final String manuSamsung1 = "sec-sgh";
public static final String manuSony = "sony";
public static final String manuHtc = "htc"; //Popular Android and WinMo manufacturer
//In some UserAgents, the only clue is the operator.
public static final String svcDocomo = "docomo";
public static final String svcKddi = "kddi";
public static final String svcVodafone = "vodafone";
//Disambiguation strings.
public static final String disUpdate = "update"; //pda vs. update
/**
* Initialize the userAgent and httpAccept variables
*
* @param userAgent the User-Agent header
* @param httpAccept the Accept header
*/
public UAgentInfo(String userAgent, String httpAccept) {
if (userAgent != null) {
this.userAgent = userAgent.toLowerCase();
}
if (httpAccept != null) {
this.httpAccept = httpAccept.toLowerCase();
}
//Intialize key stored values.
initDeviceScan();
}
/**
* Return the lower case HTTP_USER_AGENT
* @return userAgent
*/
public String getUserAgent() {
return userAgent;
}
/**
* Return the lower case HTTP_ACCEPT
* @return httpAccept
*/
public String getHttpAccept() {
return httpAccept;
}
/**
* Return whether the device is an Iphone or iPod Touch
* @return isIphone
*/
public boolean getIsIphone() {
return isIphone;
}
/**
* Return whether the device is in the Tablet Tier.
* @return isTierTablet
*/
public boolean getIsTierTablet() {
return isTierTablet;
}
/**
* Return whether the device is in the Iphone Tier.
* @return isTierIphone
*/
public boolean getIsTierIphone() {
return isTierIphone;
}
/**
* Return whether the device is in the 'Rich CSS' tier of mobile devices.
* @return isTierRichCss
*/
public boolean getIsTierRichCss() {
return isTierRichCss;
}
/**
* Return whether the device is a generic, less-capable mobile device.
* @return isTierGenericMobile
*/
public boolean getIsTierGenericMobile() {
return isTierGenericMobile;
}
/**
* Initialize Key Stored Values.
*/
public void initDeviceScan() {
//Save these properties to speed processing
this.isWebkit = detectWebkit();
this.isIphone = detectIphone();
this.isAndroid = detectAndroid();
this.isAndroidPhone = detectAndroidPhone();
//Generally, these tiers are the most useful for web development
this.isMobilePhone = detectMobileQuick();
this.isTierTablet = detectTierTablet();
this.isTierIphone = detectTierIphone();
//Optional: Comment these out if you NEVER use them
this.isTierRichCss = detectTierRichCss();
this.isTierGenericMobile = detectTierOtherPhones();
this.initCompleted = true;
}
/**
* Detects if the current device is an iPhone.
* @return detection of an iPhone
*/
public boolean detectIphone() {
// The iPad and iPod touch say they're an iPhone! So let's disambiguate.
if (userAgent.indexOf(deviceIphone) != -1 &&
!detectIpad() &&
!detectIpod()) {
return true;
}
return false;
}
/**
* Detects if the current device is an iPod Touch.
* @return detection of an iPod Touch
*/
public boolean detectIpod() {
if (userAgent.indexOf(deviceIpod) != -1) {
return true;
}
return false;
}
/**
* Detects if the current device is an iPad tablet.
* @return detection of an iPad
*/
public boolean detectIpad() {
if (userAgent.indexOf(deviceIpad) != -1
&& detectWebkit()) {
return true;
}
return false;
}
/**
* Detects if the current device is an iPhone or iPod Touch.
* @return detection of an iPhone or iPod Touch
*/
public boolean detectIphoneOrIpod() {
//We repeat the searches here because some iPods may report themselves as an iPhone, which would be okay.
if (userAgent.indexOf(deviceIphone) != -1
|| userAgent.indexOf(deviceIpod) != -1) {
return true;
}
return false;
}
/**
* Detects *any* iOS device: iPhone, iPod Touch, iPad.
* @return detection of an Apple iOS device
*/
public boolean detectIos() {
if (detectIphoneOrIpod() || detectIpad()) {
return true;
}
return false;
}
/**
* Detects *any* Android OS-based device: phone, tablet, and multi-media player.
* Also detects Google TV.
* @return detection of an Android device
*/
public boolean detectAndroid() {
if ((userAgent.indexOf(deviceAndroid) != -1) ||
detectGoogleTV())
return true;
return false;
}
/**
* Detects if the current device is a (small-ish) Android OS-based device
* used for calling and/or multi-media (like a Samsung Galaxy Player).
* Google says these devices will have 'Android' AND 'mobile' in user agent.
* Ignores tablets (Honeycomb and later).
* @return detection of an Android phone
*/
public boolean detectAndroidPhone() {
//First, let's make sure we're on an Android device.
if (!detectAndroid())
return false;
//If it's Android and has 'mobile' in it, Google says it's a phone.
if (userAgent.indexOf(mobile) != -1)
return true;
//Special check for Android devices with Opera Mobile/Mini. They should report here.
if (detectOperaMobile())
return true;
return false;
}
/**
* Detects if the current device is a (self-reported) Android tablet.
* Google says these devices will have 'Android' and NOT 'mobile' in their user agent.
* @return detection of an Android tablet
*/
public boolean detectAndroidTablet() {
//First, let's make sure we're on an Android device.
if (!detectAndroid())
return false;
//Special check for Android devices with Opera Mobile/Mini. They should NOT report here.
if (detectOperaMobile())
return false;
//Otherwise, if it's Android and does NOT have 'mobile' in it, Google says it's a tablet.
if ((userAgent.indexOf(mobile) > -1))
return false;
else
return true;
}
/**
* Detects if the current device is an Android OS-based device and
* the browser is based on WebKit.
* @return detection of an Android WebKit browser
*/
public boolean detectAndroidWebKit() {
if (detectAndroid() && detectWebkit()) {
return true;
}
return false;
}
/**
* Detects if the current device is a GoogleTV.
* @return detection of GoogleTV
*/
public boolean detectGoogleTV() {
if (userAgent.indexOf(deviceGoogleTV) != -1) {
return true;
}
return false;
}
/**
* Detects if the current browser is based on WebKit.
* @return detection of a WebKit browser
*/
public boolean detectWebkit() {
if (userAgent.indexOf(engineWebKit) != -1) {
return true;
}
return false;
}
/**
* Detects if the current browser is the Symbian S60 Open Source Browser.
* @return detection of Symbian S60 Browser
*/
public boolean detectS60OssBrowser() {
//First, test for WebKit, then make sure it's either Symbian or S60.
if (detectWebkit()
&& (userAgent.indexOf(deviceSymbian) != -1
|| userAgent.indexOf(deviceS60) != -1)) {
return true;
}
return false;
}
/**
*
* Detects if the current device is any Symbian OS-based device,
* including older S60, Series 70, Series 80, Series 90, and UIQ,
* or other browsers running on these devices.
* @return detection of SymbianOS
*/
public boolean detectSymbianOS() {
if (userAgent.indexOf(deviceSymbian) != -1
|| userAgent.indexOf(deviceS60) != -1
|| userAgent.indexOf(deviceS70) != -1
|| userAgent.indexOf(deviceS80) != -1
|| userAgent.indexOf(deviceS90) != -1) {
return true;
}
return false;
}
/**
* Detects if the current browser is a Windows Phone 7.x, 8, or 10 device
* @return detection of Windows Phone 7.x OR 8
*/
public boolean detectWindowsPhone() {
if (detectWindowsPhone7()
|| detectWindowsPhone8()
|| detectWindowsPhone10()) {
return true;
}
return false;
}
/**
* Detects a Windows Phone 7 device (in mobile browsing mode).
* @return detection of Windows Phone 7
*/
public boolean detectWindowsPhone7() {
if (userAgent.indexOf(deviceWinPhone7) != -1) {
return true;
}
return false;
}
/**
* Detects a Windows Phone 8 device (in mobile browsing mode).
* @return detection of Windows Phone 8
*/
public boolean detectWindowsPhone8() {
if (userAgent.indexOf(deviceWinPhone8) != -1) {
return true;
}
return false;
}
/**
* Detects a Windows Phone 10 device (in mobile browsing mode).
* @return detection of Windows Phone 10
*/
public boolean detectWindowsPhone10() {
if (userAgent.indexOf(deviceWinPhone10) != -1) {
return true;
}
return false;
}
/**
* Detects if the current browser is a Windows Mobile device.
* Excludes Windows Phone 7.x and 8 devices.
* Focuses on Windows Mobile 6.xx and earlier.
* @return detection of Windows Mobile
*/
public boolean detectWindowsMobile() {
if (detectWindowsPhone()) {
return false;
}
//Most devices use 'Windows CE', but some report 'iemobile'
// and some older ones report as 'PIE' for Pocket IE.
// We also look for instances of HTC and Windows for many of their WinMo devices.
if (userAgent.indexOf(deviceWinMob) != -1
|| userAgent.indexOf(deviceWinMob) != -1
|| userAgent.indexOf(deviceIeMob) != -1
|| userAgent.indexOf(enginePie) != -1
|| (userAgent.indexOf(manuHtc) != -1 && userAgent.indexOf(deviceWindows) != -1)
|| (detectWapWml() && userAgent.indexOf(deviceWindows) != -1)) {
return true;
}
//Test for Windows Mobile PPC but not old Macintosh PowerPC.
if (userAgent.indexOf(devicePpc) != -1 &&
!(userAgent.indexOf(deviceMacPpc) != -1))
return true;
return false;
}
/**
* Detects if the current browser is any BlackBerry.
* Includes BB10 OS, but excludes the PlayBook.
* @return detection of Blackberry
*/
public boolean detectBlackBerry() {
if (userAgent.indexOf(deviceBB) != -1 ||
httpAccept.indexOf(vndRIM) != -1)
return true;
if (detectBlackBerry10Phone())
return true;
return false;
}
/**
* Detects if the current browser is a BlackBerry 10 OS phone.
* Excludes tablets.
* @return detection of a Blackberry 10 device
*/
public boolean detectBlackBerry10Phone() {
if (userAgent.indexOf(deviceBB10) != -1 &&
userAgent.indexOf(mobile) != -1) {
return true;
}
return false;
}
/**
* Detects if the current browser is on a BlackBerry tablet device.
* Example: PlayBook
* @return detection of a Blackberry Tablet
*/
public boolean detectBlackBerryTablet() {
if (userAgent.indexOf(deviceBBPlaybook) != -1) {
return true;
}
return false;
}
/**
* Detects if the current browser is a BlackBerry device AND uses a
* WebKit-based browser. These are signatures for the new BlackBerry OS 6.
* Examples: Torch. Includes the Playbook.
* @return detection of a Blackberry device with WebKit browser
*/
public boolean detectBlackBerryWebKit() {
if (detectBlackBerry() &&
userAgent.indexOf(engineWebKit) != -1) {
return true;
}
return false;
}
/**
* Detects if the current browser is a BlackBerry Touch
* device, such as the Storm, Torch, and Bold Touch. Excludes the Playbook.
* @return detection of a Blackberry touchscreen device
*/
public boolean detectBlackBerryTouch() {
if (detectBlackBerry() &&
(userAgent.indexOf(deviceBBStorm) != -1 ||
userAgent.indexOf(deviceBBTorch) != -1 ||
userAgent.indexOf(deviceBBBoldTouch) != -1 ||
userAgent.indexOf(deviceBBCurveTouch) != -1 )) {
return true;
}
return false;
}
/**
* Detects if the current browser is a BlackBerry device AND
* has a more capable recent browser. Excludes the Playbook.
* Examples, Storm, Bold, Tour, Curve2
* Excludes the new BlackBerry OS 6 and 7 browser!!
* @return detection of a Blackberry device with a better browser
*/
public boolean detectBlackBerryHigh() {
//Disambiguate for BlackBerry OS 6 or 7 (WebKit) browser
if (detectBlackBerryWebKit())
return false;
if (detectBlackBerry()) {
if (detectBlackBerryTouch()
|| userAgent.indexOf(deviceBBBold) != -1
|| userAgent.indexOf(deviceBBTour) != -1
|| userAgent.indexOf(deviceBBCurve) != -1) {
return true;
} else {
return false;
}
} else {
return false;
}
}
/**
* Detects if the current browser is a BlackBerry device AND
* has an older, less capable browser.
* Examples: Pearl, 8800, Curve1
* @return detection of a Blackberry device with a poorer browser
*/
public boolean detectBlackBerryLow() {
if (detectBlackBerry()) {
//Assume that if it's not in the High tier, then it's Low
if (detectBlackBerryHigh()
|| detectBlackBerryWebKit()) {
return false;
} else {
return true;
}
} else {
return false;
}
}
/**
* Detects if the current browser is on a PalmOS device.
* @return detection of a PalmOS device
*/
public boolean detectPalmOS() {
//Most devices nowadays report as 'Palm', but some older ones reported as Blazer or Xiino.
if (userAgent.indexOf(devicePalm) != -1
|| userAgent.indexOf(engineBlazer) != -1
|| userAgent.indexOf(engineXiino) != -1) {
//Make sure it's not WebOS first
if (detectPalmWebOS()) {
return false;
} else {
return true;
}
}
return false;
}
/**
* Detects if the current browser is on a Palm device
* running the new WebOS.
* @return detection of a Palm WebOS device
*/
public boolean detectPalmWebOS() {
if (userAgent.indexOf(deviceWebOS) != -1) {
return true;
}
return false;
}
/**
* Detects if the current browser is on an HP tablet running WebOS.
* @return detection of an HP WebOS tablet
*/
public boolean detectWebOSTablet() {
if (userAgent.indexOf(deviceWebOShp) != -1 &&
userAgent.indexOf(deviceTablet) != -1) {
return true;
}
return false;
}
/**
* Detects if the current browser is on a WebOS smart TV.
* @return detection of a WebOS smart TV
*/
public boolean detectWebOSTV() {
if (userAgent.indexOf(deviceWebOStv) != -1 &&
userAgent.indexOf(smartTV2) != -1) {
return true;
}
return false;
}
/**
* Detects Opera Mobile or Opera Mini.
* @return detection of an Opera browser for a mobile device
*/
public boolean detectOperaMobile() {
if (userAgent.indexOf(engineOpera) != -1
&& (userAgent.indexOf(mini) != -1
|| userAgent.indexOf(mobi) != -1)) {
return true;
}
return false;
}
/**
* Detects if the current device is an Amazon Kindle (eInk devices only).
* Note: For the Kindle Fire, use the normal Android methods.
* @return detection of a Kindle
*/
public boolean detectKindle() {
if (userAgent.indexOf(deviceKindle)!= -1 &&
!detectAndroid()) {
return true;
}
return false;
}
/**
* Detects if the current Amazon device is using the Silk Browser.
* Note: Typically used by the the Kindle Fire.
* @return detection of an Amazon Kindle Fire in Silk mode.
*/
public boolean detectAmazonSilk() {
if (userAgent.indexOf(engineSilk) != -1) {
return true;
}
return false;
}
/**
* Detects if the current browser is a
* Garmin Nuvifone.
* @return detection of a Garmin Nuvifone
*/
public boolean detectGarminNuvifone() {
if (userAgent.indexOf(deviceNuvifone) != -1) {
return true;
}
return false;
}
/**
* Detects a device running the Bada OS from Samsung.
* @return detection of a Bada device
*/
public boolean detectBada() {
if (userAgent.indexOf(deviceBada) != -1) {
return true;
}
return false;
}
/**
* Detects a device running the Tizen smartphone OS.
* @return detection of a Tizen device
*/
public boolean detectTizen() {
if (userAgent.indexOf(deviceTizen) != -1 &&
userAgent.indexOf(mobile) != -1) {
return true;
}
return false;
}
/**
* Detects if the current browser is on a Tizen smart TV.
* @return detection of a Tizen smart TV
*/
public boolean detectTizenTV() {
if (userAgent.indexOf(deviceTizen) != -1 &&
userAgent.indexOf(smartTV1) != -1) {
return true;
}
return false;
}
/**
* Detects a device running the Meego OS.
* @return detection of a Meego device
*/
public boolean detectMeego() {
if (userAgent.indexOf(deviceMeego) != -1) {
return true;
}
return false;
}
/**
* Detects a phone running the Meego OS.
* @return detection of a Meego phone
*/
public boolean detectMeegoPhone() {
if (userAgent.indexOf(deviceMeego) != -1 &&
userAgent.indexOf(mobi) != -1) {
return true;
}
return false;
}
/**
* Detects a mobile device (probably) running the Firefox OS.
* @return detection of a Firefox OS mobile device
*/
public boolean detectFirefoxOS() {
if (detectFirefoxOSPhone() || detectFirefoxOSTablet())
return true;
return false;
}
/**
* Detects a phone (probably) running the Firefox OS.
* @return detection of a Firefox OS phone
*/
public boolean detectFirefoxOSPhone() {
//First, let's make sure we're NOT on another major mobile OS.
if (detectIos()
|| detectAndroid()
|| detectSailfish())
return false;
if ((userAgent.indexOf(engineFirefox) != -1)
&& (userAgent.indexOf(mobile) != -1))
return true;
return false;
}
/**
* Detects a tablet (probably) running the Firefox OS.
* @return detection of a Firefox OS tablet
*/
public boolean detectFirefoxOSTablet() {
//First, let's make sure we're NOT on another major mobile OS.
if (detectIos()
|| detectAndroid()
|| detectSailfish())
return false;
if ((userAgent.indexOf(engineFirefox) != -1)
&& (userAgent.indexOf(deviceTablet) != -1))
return true;
return false;
}
/**
* Detects a device running the Sailfish OS.
* @return detection of a Sailfish device
*/
public boolean detectSailfish() {
if (userAgent.indexOf(deviceSailfish) != -1) {
return true;
}
return false;
}
/**
* Detects a phone running the Sailfish OS.
* @return detection of a Sailfish phone
*/
public boolean detectSailfishPhone() {
if (detectSailfish() && (userAgent.indexOf(mobile) != -1))
return true;
return false;
}
/**
* Detects a mobile device running the Ubuntu Mobile OS.
* @return detection of an Ubuntu Mobile OS mobile device
*/
public boolean detectUbuntu() {
if (detectUbuntuPhone() || detectUbuntuTablet())
return true;
return false;
}
/**
* Detects a phone running the Ubuntu Mobile OS.
* @return detection of an Ubuntu Mobile OS phone
*/
public boolean detectUbuntuPhone() {
if ((userAgent.indexOf(deviceUbuntu) != -1)
&& (userAgent.indexOf(mobile) != -1))
return true;
return false;
}
/**
* Detects a tablet running the Ubuntu Mobile OS.
* @return detection of an Ubuntu Mobile OS tablet
*/
public boolean detectUbuntuTablet() {
if ((userAgent.indexOf(deviceUbuntu) != -1)
&& (userAgent.indexOf(deviceTablet) != -1))
return true;
return false;
}
/**
* Detects the Danger Hiptop device.
* @return detection of a Danger Hiptop
*/
public boolean detectDangerHiptop() {
if (userAgent.indexOf(deviceDanger) != -1
|| userAgent.indexOf(deviceHiptop) != -1) {
return true;
}
return false;
}
/**
* Detects if the current browser is a Sony Mylo device.
* @return detection of a Sony Mylo device
*/
public boolean detectSonyMylo() {
if (userAgent.indexOf(manuSony) != -1
&& (userAgent.indexOf(qtembedded) != -1
|| userAgent.indexOf(mylocom2) != -1)) {
return true;
}
return false;
}
/**
* Detects if the current device is on one of the Maemo-based Nokia Internet Tablets.
* @return detection of a Maemo OS tablet
*/
public boolean detectMaemoTablet() {
if (userAgent.indexOf(maemo) != -1) {
return true;
} else if (userAgent.indexOf(linux) != -1
&& userAgent.indexOf(deviceTablet) != -1
&& !detectWebOSTablet()
&& !detectAndroid()) {
return true;
}
return false;
}
/**
* Detects if the current device is an Archos media player/Internet tablet.
* @return detection of an Archos media player
*/
public boolean detectArchos() {
if (userAgent.indexOf(deviceArchos) != -1) {
return true;
}
return false;
}
/**
* Detects if the current device is an Internet-capable game console.
* Includes many handheld consoles.
* @return detection of any Game Console
*/
public boolean detectGameConsole() {
if (detectSonyPlaystation()
|| detectNintendo()
|| detectXbox()) {
return true;
}
return false;
}
/**
* Detects if the current device is a Sony Playstation.
* @return detection of Sony Playstation
*/
public boolean detectSonyPlaystation() {
if (userAgent.indexOf(devicePlaystation) != -1) {
return true;
}
return false;
}
/**
* Detects if the current device is a handheld gaming device with
* a touchscreen and modern iPhone-class browser. Includes the Playstation Vita.
* @return detection of a handheld gaming device
*/
public boolean detectGamingHandheld() {
if ((userAgent.indexOf(devicePlaystation) != -1) &&
(userAgent.indexOf(devicePlaystationVita) != -1)) {
return true;
}
return false;
}
/**
* Detects if the current device is a Nintendo game device.
* @return detection of Nintendo
*/
public boolean detectNintendo() {
if (userAgent.indexOf(deviceNintendo) != -1
|| userAgent.indexOf(deviceWii) != -1
|| userAgent.indexOf(deviceNintendoDs) != -1) {
return true;
}
return false;
}
/**
* Detects if the current device is a Microsoft Xbox.
* @return detection of Xbox
*/
public boolean detectXbox() {
if (userAgent.indexOf(deviceXbox) != -1) {
return true;
}
return false;
}
/**
* Detects whether the device is a Brew-powered device.
* @return detection of a Brew device
*/
public boolean detectBrewDevice() {
if (userAgent.indexOf(deviceBrew) != -1) {
return true;
}
return false;
}
/**
* Detects whether the device supports WAP or WML.
* @return detection of a WAP- or WML-capable device
*/
public boolean detectWapWml() {
if (httpAccept.indexOf(vndwap) != -1
|| httpAccept.indexOf(wml) != -1) {
return true;
}
return false;
}
/**
* Detects if the current device supports MIDP, a mobile Java technology.
* @return detection of a MIDP mobile Java-capable device
*/
public boolean detectMidpCapable() {
if (userAgent.indexOf(deviceMidp) != -1
|| httpAccept.indexOf(deviceMidp) != -1) {
return true;
}
return false;
}
//*****************************
// Device Classes
//*****************************
/**
* Check to see whether the device is any device
* in the 'smartphone' category.
* @return detection of a general smartphone device
*/
public boolean detectSmartphone() {
//Exclude duplicates from TierIphone
return (detectTierIphone()
|| detectS60OssBrowser()
|| detectSymbianOS()
|| detectWindowsMobile()
|| detectBlackBerry()
|| detectMeegoPhone()
|| detectPalmOS());
}
/**
* Detects if the current device is a mobile device.
* This method catches most of the popular modern devices.
* Excludes Apple iPads and other modern tablets.
* @return detection of any mobile device using the quicker method
*/
public boolean detectMobileQuick() {
//Let's exclude tablets
if (isTierTablet) {
return false;
}
//Most mobile browsing is done on smartphones
if (detectSmartphone()) {
return true;
}
//Catch-all for many mobile devices
if (userAgent.indexOf(mobile) != -1) {
return true;
}
if (detectOperaMobile()) {
return true;
}
//We also look for Kindle devices
if (detectKindle()
|| detectAmazonSilk()) {
return true;
}
if (detectWapWml()
|| detectMidpCapable()
|| detectBrewDevice()) {
return true;
}
if ((userAgent.indexOf(engineNetfront) != -1)
|| (userAgent.indexOf(engineUpBrowser) != -1)) {
return true;
}
return false;
}
/**
* The longer and more thorough way to detect for a mobile device.
* Will probably detect most feature phones,
* smartphone-class devices, Internet Tablets,
* Internet-enabled game consoles, etc.
* This ought to catch a lot of the more obscure and older devices, also --
* but no promises on thoroughness!
* @return detection of any mobile device using the more thorough method
*/
public boolean detectMobileLong() {
if (detectMobileQuick()
|| detectGameConsole()) {
return true;
}
if (detectDangerHiptop()
|| detectMaemoTablet()
|| detectSonyMylo()
|| detectArchos()) {
return true;
}
if ((userAgent.indexOf(devicePda) != -1) &&
(userAgent.indexOf(disUpdate) < 0)) //no index found
{
return true;
}
//Detect older phones from certain manufacturers and operators.
if ((userAgent.indexOf(uplink) != -1)
|| (userAgent.indexOf(engineOpenWeb) != -1)
|| (userAgent.indexOf(manuSamsung1) != -1)
|| (userAgent.indexOf(manuSonyEricsson) != -1)
|| (userAgent.indexOf(manuericsson) != -1)
|| (userAgent.indexOf(svcDocomo) != -1)
|| (userAgent.indexOf(svcKddi) != -1)
|| (userAgent.indexOf(svcVodafone) != -1))
{
return true;
}
return false;
}
//*****************************
// For Mobile Web Site Design
//*****************************
/**
* The quick way to detect for a tier of devices.
* This method detects for the new generation of
* HTML 5 capable, larger screen tablets.
* Includes iPad, Android (e.g., Xoom), BB Playbook, WebOS, etc.
* @return detection of any device in the Tablet Tier
*/
public boolean detectTierTablet() {
if (detectIpad()
|| detectAndroidTablet()
|| detectBlackBerryTablet()
|| detectFirefoxOSTablet()
|| detectUbuntuTablet()
|| detectWebOSTablet()) {
return true;
}
return false;
}
/**
* The quick way to detect for a tier of devices.
* This method detects for devices which can
* display iPhone-optimized web content.
* Includes iPhone, iPod Touch, Android, Windows Phone 7 and 8, BB10, WebOS, Playstation Vita, etc.
* @return detection of any device in the iPhone/Android/Windows Phone/BlackBerry/WebOS Tier
*/
public boolean detectTierIphone() {
if (detectIphoneOrIpod()
|| detectAndroidPhone()
|| detectWindowsPhone()
|| detectBlackBerry10Phone()
|| (detectBlackBerryWebKit()
&& detectBlackBerryTouch())
|| detectPalmWebOS()
|| detectBada()
|| detectTizen()
|| detectFirefoxOSPhone()
|| detectSailfishPhone()
|| detectUbuntuPhone()
|| detectGamingHandheld()) {
return true;
}
return false;
}
/**
* The quick way to detect for a tier of devices.
* This method detects for devices which are likely to be capable
* of viewing CSS content optimized for the iPhone,
* but may not necessarily support JavaScript.
* Excludes all iPhone Tier devices.
* @return detection of any device in the 'Rich CSS' Tier
*/
public boolean detectTierRichCss() {
boolean result = false;
//The following devices are explicitly ok.
//Note: 'High' BlackBerry devices ONLY
if (detectMobileQuick()) {
//Exclude iPhone Tier and e-Ink Kindle devices.
if (!detectTierIphone() && !detectKindle()) {
//The following devices are explicitly ok.
//Note: 'High' BlackBerry devices ONLY
//Older Windows 'Mobile' isn't good enough for iPhone Tier.
if (detectWebkit()
|| detectS60OssBrowser()
|| detectBlackBerryHigh()
|| detectWindowsMobile()
|| userAgent.indexOf(engineTelecaQ) != -1) {
result= true;
} // if detectWebkit()
} //if !detectTierIphone()
} //if detectMobileQuick()
return result;
}
/**
* The quick way to detect for a tier of devices.
* This method detects for all other types of phones,
* but excludes the iPhone and RichCSS Tier devices.
* @return detection of a mobile device in the less capable tier
*/
public boolean detectTierOtherPhones() {
//Exclude devices in the other 2 categories
if (detectMobileLong()
&& !detectTierIphone()
&& !detectTierRichCss()) {
return true;
}
return false;
}
}
================================================
FILE: JavaScript/mdetect.js
================================================
/* *******************************************
// Copyright 2010-2015, Anthony Hand
//
// BETA NOTICE
// Previous versions of the JavaScript code for MobileESP were 'regular'
// JavaScript. The strength of it was that it was really easy to code and use.
// Unfortunately, regular JavaScript means that all variables and functions
// are in the global namespace. There can be collisions with other code libraries
// which may have similar variable or function names. Collisions cause bugs as each
// library changes a variable's definition or functionality unexpectedly.
// As a result, we thought it wise to switch to an "object oriented" style of code.
// This 'literal notation' technique keeps all MobileESP variables and functions fully self-contained.
// It avoids potential for collisions with other JavaScript libraries.
// This technique allows the developer continued access to any desired function or property.
//
// Please send feedback to project founder Anthony Hand: anthony.hand@gmail.com
//
//
// File version 2015.05.13 (May 13, 2015)
// Updates:
// - Moved MobileESP to GitHub. https://github.com/ahand/mobileesp
// - Opera Mobile/Mini browser has the same UA string on multiple platforms and doesn't differentiate phone vs. tablet.
// - Removed DetectOperaAndroidPhone(). This method is no longer reliable.
// - Removed DetectOperaAndroidTablet(). This method is no longer reliable.
// - Added support for Windows Phone 10: variable and DetectWindowsPhone10()
// - Updated DetectWindowsPhone() to include WP10.
// - Added support for Firefox OS.
// - A variable plus DetectFirefoxOS(), DetectFirefoxOSPhone(), DetectFirefoxOSTablet()
// - NOTE: Firefox doesn't add UA tokens to definitively identify Firefox OS vs. their browsers on other mobile platforms.
// - Added support for Sailfish OS. Not enough info to add a tablet detection method at this time.
// - A variable plus DetectSailfish(), DetectSailfishPhone()
// - Added support for Ubuntu Mobile OS.
// - DetectUbuntu(), DetectUbuntuPhone(), DetectUbuntuTablet()
// - Added support for 2 smart TV OSes. They lack browsers but do have WebViews for use by HTML apps.
// - One variable for Samsung Tizen TVs, plus DetectTizenTV()
// - One variable for LG WebOS TVs, plus DetectWebOSTV()
// - Updated DetectTizen(). Now tests for “mobile” to disambiguate from Samsung Smart TVs
// - Removed variables for obsolete devices: deviceHtcFlyer, deviceXoom.
// - Updated DetectAndroid(). No longer has a special test case for the HTC Flyer tablet.
// - Updated DetectAndroidPhone().
// - Updated internal detection code for Android.
// - No longer has a special test case for the HTC Flyer tablet.
// - Checks against DetectOperaMobile() on Android and reports here if relevant.
// - Updated DetectAndroidTablet().
// - No longer has a special test case for the HTC Flyer tablet.
// - Checks against DetectOperaMobile() on Android to exclude it from here.
// - DetectMeego(): Changed definition for this method. Now detects any Meego OS device, not just phones.
// - DetectMeegoPhone(): NEW. For Meego phones. Ought to detect Opera browsers on Meego, as well.
// - DetectTierIphone(): Added support for phones running Sailfish, Ubuntu and Firefox Mobile.
// - DetectTierTablet(): Added support for tablets running Ubuntu and Firefox Mobile.
// - DetectSmartphone(): Added support for Meego phones.
// - Reorganized DetectMobileQuick(). Moved the following to DetectMobileLong():
// - DetectDangerHiptop(), DetectMaemoTablet(), DetectSonyMylo(), DetectArchos()
//
//
//
// LICENSE INFORMATION
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific
// language governing permissions and limitations under the License.
//
//
// ABOUT THIS PROJECT
// Project Owner: Anthony Hand
// Email: anthony.hand@gmail.com
// Web Site: http://www.mobileesp.com
// Source Files: https://github.com/ahand/mobileesp
//
// Versions of this code are available for:
// PHP, JavaScript, Java, ASP.NET (C#), Ruby and others
//
//
// WARNING:
// These JavaScript-based device detection features may ONLY work
// for the newest generation of smartphones, such as the iPhone,
// Android and Palm WebOS devices.
// These device detection features may NOT work for older smartphones
// which had poor support for JavaScript, including
// older BlackBerry, PalmOS, and Windows Mobile devices.
// Additionally, because JavaScript support is extremely poor among
// 'feature phones', these features may not work at all on such devices.
// For better results, consider using a server-based version of this code,
// such as Java, APS.NET, PHP, or Ruby.
//
// *******************************************
*/
var MobileEsp = {
//GLOBALLY USEFUL VARIABLES
//Note: These values are set automatically during the Init function.
//Stores whether we're currently initializing the most popular functions.
initCompleted : false,
isWebkit : false, //Stores the result of DetectWebkit()
isMobilePhone : false, //Stores the result of DetectMobileQuick()
isIphone : false, //Stores the result of DetectIphone()
isAndroid : false, //Stores the result of DetectAndroid()
isAndroidPhone : false, //Stores the result of DetectAndroidPhone()
isTierTablet : false, //Stores the result of DetectTierTablet()
isTierIphone : false, //Stores the result of DetectTierIphone()
isTierRichCss : false, //Stores the result of DetectTierRichCss()
isTierGenericMobile : false, //Stores the result of DetectTierOtherPhones()
//INTERNALLY USED DETECTION STRING VARIABLES
engineWebKit : 'webkit',
deviceIphone : 'iphone',
deviceIpod : 'ipod',
deviceIpad : 'ipad',
deviceMacPpc : 'macintosh', //Used for disambiguation
deviceAndroid : 'android',
deviceGoogleTV : 'googletv',
deviceWinPhone7 : 'windows phone os 7',
deviceWinPhone8 : 'windows phone 8',
deviceWinPhone10 : 'windows phone 10',
deviceWinMob : 'windows ce',
deviceWindows : 'windows',
deviceIeMob : 'iemobile',
devicePpc : 'ppc', //Stands for PocketPC
enginePie : 'wm5 pie', //An old Windows Mobile
deviceBB : 'blackberry',
deviceBB10 : 'bb10', //For the new BB 10 OS
vndRIM : 'vnd.rim', //Detectable when BB devices emulate IE or Firefox
deviceBBStorm : 'blackberry95', //Storm 1 and 2
deviceBBBold : 'blackberry97', //Bold 97x0 (non-touch)
deviceBBBoldTouch : 'blackberry 99', //Bold 99x0 (touchscreen)
deviceBBTour : 'blackberry96', //Tour
deviceBBCurve : 'blackberry89', //Curve 2
deviceBBCurveTouch : 'blackberry 938', //Curve Touch 9380
deviceBBTorch : 'blackberry 98', //Torch
deviceBBPlaybook : 'playbook', //PlayBook tablet
deviceSymbian : 'symbian',
deviceSymbos : 'symbos', //Opera 10 on Symbian
deviceS60 : 'series60',
deviceS70 : 'series70',
deviceS80 : 'series80',
deviceS90 : 'series90',
devicePalm : 'palm',
deviceWebOS : 'webos', //For Palm devices
deviceWebOStv : 'web0s', //For LG TVs
deviceWebOShp : 'hpwos', //For HP's line of WebOS devices
deviceNuvifone : 'nuvifone', //Garmin Nuvifone
deviceBada : 'bada', //Samsung's Bada OS
deviceTizen : 'tizen', //Tizen OS
deviceMeego : 'meego', //Meego OS
deviceSailfish : 'sailfish', //Sailfish OS
deviceUbuntu : 'ubuntu', //Ubuntu Mobile OS
deviceKindle : 'kindle', //Amazon eInk Kindle
engineSilk : 'silk-accelerated', //Amazon's accelerated Silk browser for Kindle Fire
engineBlazer : 'blazer', //Old Palm browser
engineXiino : 'xiino',
//Initialize variables for mobile-specific content.
vndwap : 'vnd.wap',
wml : 'wml',
//Initialize variables for random devices and mobile browsers.
//Some of these may not support JavaScript
deviceTablet : 'tablet',
deviceBrew : 'brew',
deviceDanger : 'danger',
deviceHiptop : 'hiptop',
devicePlaystation : 'playstation',
devicePlaystationVita : 'vita',
deviceNintendoDs : 'nitro',
deviceNintendo : 'nintendo',
deviceWii : 'wii',
deviceXbox : 'xbox',
deviceArchos : 'archos',
engineFirefox : 'firefox', //For Firefox OS
engineOpera : 'opera', //Popular browser
engineNetfront : 'netfront', //Common embedded OS browser
engineUpBrowser : 'up.browser', //common on some phones
deviceMidp : 'midp', //a mobile Java technology
uplink : 'up.link',
engineTelecaQ : 'teleca q', //a modern feature phone browser
engineObigo : 'obigo', //W 10 is a modern feature phone browser
devicePda : 'pda',
mini : 'mini', //Some mobile browsers put 'mini' in their names
mobile : 'mobile', //Some mobile browsers put 'mobile' in their user agent strings
mobi : 'mobi', //Some mobile browsers put 'mobi' in their user agent strings
//Smart TV strings
smartTV1 : 'smart-tv', //Samsung Tizen smart TVs
smartTV2 : 'smarttv', //LG WebOS smart TVs
//Use Maemo, Tablet, and Linux to test for Nokia's Internet Tablets.
maemo : 'maemo',
linux : 'linux',
mylocom2 : 'sony/com', // for Sony Mylo 1 and 2
//In some UserAgents, the only clue is the manufacturer
manuSonyEricsson : 'sonyericsson',
manuericsson : 'ericsson',
manuSamsung1 : 'sec-sgh',
manuSony : 'sony',
manuHtc : 'htc', //Popular Android and WinMo manufacturer
//In some UserAgents, the only clue is the operator
svcDocomo : 'docomo',
svcKddi : 'kddi',
svcVodafone : 'vodafone',
//Disambiguation strings.
disUpdate : 'update', //pda vs. update
//Holds the User Agent string value.
uagent : '',
//Initializes key MobileEsp variables
InitDeviceScan : function() {
this.initCompleted = false;
if (navigator && navigator.userAgent)
this.uagent = navigator.userAgent.toLowerCase();
//Save these properties to speed processing
this.isWebkit = this.DetectWebkit();
this.isIphone = this.DetectIphone();
this.isAndroid = this.DetectAndroid();
this.isAndroidPhone = this.DetectAndroidPhone();
//Generally, these tiers are the most useful for web development
this.isMobilePhone = this.DetectMobileQuick();
this.isTierIphone = this.DetectTierIphone();
this.isTierTablet = this.DetectTierTablet();
//Optional: Comment these out if you NEVER use them
this.isTierRichCss = this.DetectTierRichCss();
this.isTierGenericMobile = this.DetectTierOtherPhones();
this.initCompleted = true;
},
//APPLE IOS
//**************************
// Detects if the current device is an iPhone.
DetectIphone : function() {
if (this.initCompleted || this.isIphone)
return this.isIphone;
if (this.uagent.search(this.deviceIphone) > -1)
{
//The iPad and iPod Touch say they're an iPhone! So let's disambiguate.
if (this.DetectIpad() || this.DetectIpod())
return false;
//Yay! It's an iPhone!
else
return true;
}
else
return false;
},
//**************************
// Detects if the current device is an iPod Touch.
DetectIpod : function() {
if (this.uagent.search(this.deviceIpod) > -1)
return true;
else
return false;
},
//**************************
// Detects if the current device is an iPhone or iPod Touch.
DetectIphoneOrIpod : function() {
//We repeat the searches here because some iPods
// may report themselves as an iPhone, which is ok.
if (this.DetectIphone() || this.DetectIpod())
return true;
else
return false;
},
//**************************
// Detects if the current device is an iPad tablet.
DetectIpad : function() {
if (this.uagent.search(this.deviceIpad) > -1 && this.DetectWebkit())
return true;
else
return false;
},
//**************************
// Detects *any* iOS device: iPhone, iPod Touch, iPad.
DetectIos : function() {
if (this.DetectIphoneOrIpod() || this.DetectIpad())
return true;
else
return false;
},
//ANDROID
//**************************
// Detects *any* Android OS-based device: phone, tablet, and multi-media player.
// Also detects Google TV.
DetectAndroid : function() {
if (this.initCompleted || this.isAndroid)
return this.isAndroid;
if ((this.uagent.search(this.deviceAndroid) > -1) || this.DetectGoogleTV())
return true;
return false;
},
//**************************
// Detects if the current device is a (small-ish) Android OS-based device
// used for calling and/or multi-media (like a Samsung Galaxy Player).
// Google says these devices will have 'Android' AND 'mobile' in user agent.
// Ignores tablets (Honeycomb and later).
DetectAndroidPhone : function() {
if (this.initCompleted || this.isAndroidPhone)
return this.isAndroidPhone;
//First, let's make sure we're on an Android device.
if (!this.DetectAndroid())
return false;
//If it's Android and has 'mobile' in it, Google says it's a phone.
if (this.uagent.search(this.mobile) > -1)
return true;
//Special check for Android phones with Opera Mobile. They should report here.
if (this.DetectOperaMobile())
return true;
return false;
},
//**************************
// Detects if the current device is a (self-reported) Android tablet.
// Google says these devices will have 'Android' and NOT 'mobile' in their user agent.
DetectAndroidTablet : function() {
//First, let's make sure we're on an Android device.
if (!this.DetectAndroid())
return false;
//Special check for Opera Android Phones. They should NOT report here.
if (this.DetectOperaMobile())
return false;
//Otherwise, if it's Android and does NOT have 'mobile' in it, Google says it's a tablet.
if (this.uagent.search(this.mobile) > -1)
return false;
else
return true;
},
//**************************
// Detects if the current device is an Android OS-based device and
// the browser is based on WebKit.
DetectAndroidWebKit : function() {
if (this.DetectAndroid() && this.DetectWebkit())
return true;
else
return false;
},
//**************************
// Detects if the current device is a GoogleTV.
DetectGoogleTV : function() {
if (this.uagent.search(this.deviceGoogleTV) > -1)
return true;
else
return false;
},
//**************************
// Detects if the current browser is based on WebKit.
DetectWebkit : function() {
if (this.initCompleted || this.isWebkit)
return this.isWebkit;
if (this.uagent.search(this.engineWebKit) > -1)
return true;
else
return false;
},
//WINDOWS MOBILE AND PHONE
// Detects if the current browser is a
// Windows Phone 7, 8, or 10 device.
DetectWindowsPhone : function() {
if (this.DetectWindowsPhone7() ||
this.DetectWindowsPhone8() ||
this.DetectWindowsPhone10())
return true;
else
return false;
},
//**************************
// Detects a Windows Phone 7 device (in mobile browsing mode).
DetectWindowsPhone7 : function() {
if (this.uagent.search(this.deviceWinPhone7) > -1)
return true;
else
return false;
},
//**************************
// Detects a Windows Phone 8 device (in mobile browsing mode).
DetectWindowsPhone8 : function() {
if (this.uagent.search(this.deviceWinPhone8) > -1)
return true;
else
return false;
},
//**************************
// Detects a Windows Phone 10 device (in mobile browsing mode).
DetectWindowsPhone10 : function() {
if (this.uagent.search(this.deviceWinPhone10) > -1)
return true;
else
return false;
},
//**************************
// Detects if the current browser is a Windows Mobile device.
// Excludes Windows Phone 7 and later devices.
// Focuses on Windows Mobile 6.xx and earlier.
DetectWindowsMobile : function() {
if (this.DetectWindowsPhone())
return false;
//Most devices use 'Windows CE', but some report 'iemobile'
// and some older ones report as 'PIE' for Pocket IE.
if (this.uagent.search(this.deviceWinMob) > -1 ||
this.uagent.search(this.deviceIeMob) > -1 ||
this.uagent.search(this.enginePie) > -1)
return true;
//Test for Windows Mobile PPC but not old Macintosh PowerPC.
if ((this.uagent.search(this.devicePpc) > -1) &&
!(this.uagent.search(this.deviceMacPpc) > -1))
return true;
//Test for Windwos Mobile-based HTC devices.
if (this.uagent.search(this.manuHtc) > -1 &&
this.uagent.search(this.deviceWindows) > -1)
return true;
else
return false;
},
//BLACKBERRY
//**************************
// Detects if the current browser is a BlackBerry of some sort.
// Includes BB10 OS, but excludes the PlayBook.
DetectBlackBerry : function() {
if ((this.uagent.search(this.deviceBB) > -1) ||
(this.uagent.search(this.vndRIM) > -1))
return true;
if (this.DetectBlackBerry10Phone())
return true;
else
return false;
},
//**************************
// Detects if the current browser is a BlackBerry 10 OS phone.
// Excludes tablets.
DetectBlackBerry10Phone : function() {
if ((this.uagent.search(this.deviceBB10) > -1) &&
(this.uagent.search(this.mobile) > -1))
return true;
else
return false;
},
//**************************
// Detects if the current browser is on a BlackBerry tablet device.
// Example: PlayBook
DetectBlackBerryTablet : function() {
if (this.uagent.search(this.deviceBBPlaybook) > -1)
return true;
else
return false;
},
//**************************
// Detects if the current browser is a BlackBerry device AND uses a
// WebKit-based browser. These are signatures for the new BlackBerry OS 6.
// Examples: Torch. Includes the Playbook.
DetectBlackBerryWebKit : function() {
if (this.DetectBlackBerry() &&
this.uagent.search(this.engineWebKit) > -1)
return true;
else
return false;
},
//**************************
// Detects if the current browser is a BlackBerry Touch
// device, such as the Storm, Torch, and Bold Touch. Excludes the Playbook.
DetectBlackBerryTouch : function() {
if (this.DetectBlackBerry() &&
((this.uagent.search(this.deviceBBStorm) > -1) ||
(this.uagent.search(this.deviceBBTorch) > -1) ||
(this.uagent.search(this.deviceBBBoldTouch) > -1) ||
(this.uagent.search(this.deviceBBCurveTouch) > -1) ))
return true;
else
return false;
},
//**************************
// Detects if the current browser is a BlackBerry OS 5 device AND
// has a more capable recent browser. Excludes the Playbook.
// Examples, Storm, Bold, Tour, Curve2
// Excludes the new BlackBerry OS 6 and 7 browser!!
DetectBlackBerryHigh : function() {
//Disambiguate for BlackBerry OS 6 or 7 (WebKit) browser
if (this.DetectBlackBerryWebKit())
return false;
if ((this.DetectBlackBerry()) &&
(this.DetectBlackBerryTouch() ||
this.uagent.search(this.deviceBBBold) > -1 ||
this.uagent.search(this.deviceBBTour) > -1 ||
this.uagent.search(this.deviceBBCurve) > -1))
return true;
else
return false;
},
//**************************
// Detects if the current browser is a BlackBerry device AND
// has an older, less capable browser.
// Examples: Pearl, 8800, Curve1.
DetectBlackBerryLow : function() {
if (this.DetectBlackBerry())
{
//Assume that if it's not in the High tier or has WebKit, then it's Low.
if (this.DetectBlackBerryHigh() || this.DetectBlackBerryWebKit())
return false;
else
return true;
}
else
return false;
},
//SYMBIAN
//**************************
// Detects if the current browser is the Nokia S60 Open Source Browser.
DetectS60OssBrowser : function() {
if (this.DetectWebkit())
{
if ((this.uagent.search(this.deviceS60) > -1 ||
this.uagent.search(this.deviceSymbian) > -1))
return true;
else
return false;
}
else
return false;
},
//**************************
// Detects if the current device is any Symbian OS-based device,
// including older S60, Series 70, Series 80, Series 90, and UIQ,
// or other browsers running on these devices.
DetectSymbianOS : function() {
if (this.uagent.search(this.deviceSymbian) > -1 ||
this.uagent.search(this.deviceS60) > -1 ||
((this.uagent.search(this.deviceSymbos) > -1) &&
(this.DetectOperaMobile)) || //Opera 10
this.uagent.search(this.deviceS70) > -1 ||
this.uagent.search(this.deviceS80) > -1 ||
this.uagent.search(this.deviceS90) > -1)
return true;
else
return false;
},
//WEBOS AND PALM
//**************************
// Detects if the current browser is on a PalmOS device.
DetectPalmOS : function() {
//Make sure it's not WebOS first
if (this.DetectPalmWebOS())
return false;
//Most devices nowadays report as 'Palm',
// but some older ones reported as Blazer or Xiino.
if (this.uagent.search(this.devicePalm) > -1 ||
this.uagent.search(this.engineBlazer) > -1 ||
this.uagent.search(this.engineXiino) > -1)
return true;
else
return false;
},
//**************************
// Detects if the current browser is on a Palm device
// running the new WebOS.
DetectPalmWebOS : function()
{
if (this.uagent.search(this.deviceWebOS) > -1)
return true;
else
return false;
},
//**************************
// Detects if the current browser is on an HP tablet running WebOS.
DetectWebOSTablet : function() {
if (this.uagent.search(this.deviceWebOShp) > -1 &&
this.uagent.search(this.deviceTablet) > -1)
return true;
else
return false;
},
//**************************
// Detects if the current browser is on a WebOS smart TV.
DetectWebOSTV : function() {
if (this.uagent.search(this.deviceWebOStv) > -1 &&
this.uagent.search(this.smartTV2) > -1)
return true;
else
return false;
},
//OPERA
//**************************
// Detects if the current browser is Opera Mobile or Mini.
// Note: Older embedded Opera on mobile devices didn't follow these naming conventions.
// Like Archos media players, they will probably show up in DetectMobileQuick or -Long instead.
DetectOperaMobile : function() {
if ((this.uagent.search(this.engineOpera) > -1) &&
((this.uagent.search(this.mini) > -1 ||
this.uagent.search(this.mobi) > -1)))
return true;
else
return false;
},
//MISCELLANEOUS DEVICES
//**************************
// Detects if the current device is an Amazon Kindle (eInk devices only).
// Note: For the Kindle Fire, use the normal Android methods.
DetectKindle : function() {
if (this.uagent.search(this.deviceKindle) > -1 &&
!this.DetectAndroid())
return true;
else
return false;
},
//**************************
// Detects if the current Amazon device has turned on the Silk accelerated browsing feature.
// Note: Typically used by the the Kindle Fire.
DetectAmazonSilk : function() {
if (this.uagent.search(this.engineSilk) > -1)
return true;
else
return false;
},
//**************************
// Detects if the current browser is a
// Garmin Nuvifone.
DetectGarminNuvifone : function() {
if (this.uagent.search(this.deviceNuvifone) > -1)
return true;
else
return false;
},
//**************************
// Detects a device running the Bada OS from Samsung.
DetectBada : function() {
if (this.uagent.search(this.deviceBada) > -1)
return true;
else
return false;
},
//**************************
// Detects a device running the Tizen smartphone OS.
DetectTizen : function() {
if (this.uagent.search(this.deviceTizen) > -1 &&
this.uagent.search(this.mobile) > -1)
return true;
else
return false;
},
//**************************
// Detects if the current browser is on a Tizen smart TV.
DetectTizenTV : function() {
if (this.uagent.search(this.deviceTizen) > -1 &&
this.uagent.search(this.smartTV1) > -1)
return true;
else
return false;
},
//**************************
// Detects a device running the Meego OS.
DetectMeego : function() {
if (this.uagent.search(this.deviceMeego) > -1)
return true;
else
return false;
},
//**************************
// Detects a phone running the Meego OS.
DetectMeegoPhone : function() {
if (this.uagent.search(this.deviceMeego) > -1 &&
this.uagent.search(this.mobi) > -1)
return true;
else
return false;
},
//**************************
// Detects a mobile device (probably) running the Firefox OS.
DetectFirefoxOS : function() {
if (this.DetectFirefoxOSPhone() || this.DetectFirefoxOSTablet())
return true;
else
return false;
},
//**************************
// Detects a phone (probably) running the Firefox OS.
DetectFirefoxOSPhone : function() {
//First, let's make sure we're NOT on another major mobile OS.
if (this.DetectIos() ||
this.DetectAndroid() ||
this.DetectSailfish())
return false;
if ((this.uagent.search(this.engineFirefox) > -1) &&
(this.uagent.search(this.mobile) > -1))
return true;
return false;
},
//**************************
// Detects a tablet (probably) running the Firefox OS.
DetectFirefoxOSTablet : function() {
//First, let's make sure we're NOT on another major mobile OS.
if (this.DetectIos() ||
this.DetectAndroid() ||
this.DetectSailfish())
return false;
if ((this.uagent.search(this.engineFirefox) > -1) &&
(this.uagent.search(this.deviceTablet) > -1))
return true;
return false;
},
//**************************
// Detects a device running the Sailfish OS.
DetectSailfish : function() {
if (this.uagent.search(this.deviceSailfish) > -1)
return true;
else
return false;
},
//**************************
// Detects a phone running the Sailfish OS.
DetectSailfishPhone : function() {
if (this.DetectSailfish() && (this.uagent.search(this.mobile) > -1))
return true;
return false;
},
//**************************
// Detects a mobile device running the Ubuntu Mobile OS.
DetectUbuntu : function() {
if (this.DetectUbuntuPhone() || this.DetectUbuntuTablet())
return true;
else
return false;
},
//**************************
// Detects a phone running the Ubuntu Mobile OS.
DetectUbuntuPhone : function() {
if ((this.uagent.search(this.deviceUbuntu) > -1) &&
(this.uagent.search(this.mobile) > -1))
return true;
return false;
},
//**************************
// Detects a tablet running the Ubuntu Mobile OS.
DetectUbuntuTablet : function() {
if ((this.uagent.search(this.deviceUbuntu) > -1) &&
(this.uagent.search(this.deviceTablet) > -1))
return true;
return false;
},
//**************************
// Detects the Danger Hiptop device.
DetectDangerHiptop : function() {
if (this.uagent.search(this.deviceDanger) > -1 ||
this.uagent.search(this.deviceHiptop) > -1)
return true;
else
return false;
},
//**************************
// Detects if the current browser is a Sony Mylo device.
DetectSonyMylo : function() {
if ((this.uagent.search(this.manuSony) > -1) &&
((this.uagent.search(this.qtembedded) > -1) ||
(this.uagent.search(this.mylocom2) > -1)))
return true;
else
return false;
},
//**************************
// Detects if the current device is on one of
// the Maemo-based Nokia Internet Tablets.
DetectMaemoTablet : function() {
if (this.uagent.search(this.maemo) > -1)
return true;
//For Nokia N810, must be Linux + Tablet, or else it could be something else.
if ((this.uagent.search(this.linux) > -1) &&
(this.uagent.search(this.deviceTablet) > -1) &&
this.DetectWebOSTablet() &&
!this.DetectAndroid())
return true;
else
return false;
},
//**************************
// Detects if the current device is an Archos media player/Internet tablet.
DetectArchos : function() {
if (this.uagent.search(this.deviceArchos) > -1)
return true;
else
return false;
},
//**************************
// Detects if the current device is an Internet-capable game console.
// Includes many handheld consoles.
DetectGameConsole : function() {
if (this.DetectSonyPlaystation() ||
this.DetectNintendo() ||
this.DetectXbox())
return true;
else
return false;
},
//**************************
// Detects if the current device is a Sony Playstation.
DetectSonyPlaystation : function() {
if (this.uagent.search(this.devicePlaystation) > -1)
return true;
else
return false;
},
//**************************
// Detects if the current device is a handheld gaming device with
// a touchscreen and modern iPhone-class browser. Includes the Playstation Vita.
DetectGamingHandheld : function() {
if ((this.uagent.search(this.devicePlaystation) > -1) &&
(this.uagent.search(this.devicePlaystationVita) > -1))
return true;
else
return false;
},
//**************************
// Detects if the current device is a Nintendo game device.
DetectNintendo : function() {
if (this.uagent.search(this.deviceNintendo) > -1 ||
this.uagent.search(this.deviceWii) > -1 ||
this.uagent.search(this.deviceNintendoDs) > -1)
return true;
else
return false;
},
//**************************
// Detects if the current device is a Microsoft Xbox.
DetectXbox : function() {
if (this.uagent.search(this.deviceXbox) > -1)
return true;
else
return false;
},
//**************************
// Detects whether the device is a Brew-powered device.
// Note: Limited to older Brew-powered feature phones.
// Ignores newer Brew versions like MP. Refer to DetectMobileQuick().
DetectBrewDevice : function() {
if (this.uagent.search(this.deviceBrew) > -1)
return true;
else
return false;
},
// DEVICE CLASSES
//**************************
// Check to see whether the device is *any* 'smartphone'.
// Note: It's better to use DetectTierIphone() for modern touchscreen devices.
DetectSmartphone : function() {
//Exclude duplicates from TierIphone
if (this.DetectTierIphone() ||
this.DetectS60OssBrowser() ||
this.DetectSymbianOS() ||
this.DetectWindowsMobile() ||
this.DetectBlackBerry() ||
this.DetectMeegoPhone() ||
this.DetectPalmOS())
return true;
//Otherwise, return false.
return false;
},
//**************************
// Detects if the current device is a mobile device.
// This method catches most of the popular modern devices.
// Excludes Apple iPads and other modern tablets.
DetectMobileQuick : function() {
if (this.initCompleted || this.isMobilePhone)
return this.isMobilePhone;
//Let's exclude tablets.
if (this.DetectTierTablet())
return false;
//Most mobile browsing is done on smartphones
if (this.DetectSmartphone())
return true;
//Catch-all for many mobile devices
if (this.uagent.search(this.mobile) > -1)
return true;
if (this.DetectOperaMobile())
return true;
//We also look for Kindle devices
if (this.DetectKindle() ||
this.DetectAmazonSilk())
return true;
if (this.uagent.search(this.deviceMidp) > -1 ||
this.DetectBrewDevice())
return true;
if ((this.uagent.search(this.engineObigo) > -1) ||
(this.uagent.search(this.engineNetfront) > -1) ||
(this.uagent.search(this.engineUpBrowser) > -1))
return true;
return false;
},
//**************************
// Detects in a more comprehensive way if the current device is a mobile device.
DetectMobileLong : function() {
if (this.DetectMobileQuick())
return true;
if (this.DetectGameConsole())
return true;
if (this.DetectDangerHiptop() ||
this.DetectMaemoTablet() ||
this.DetectSonyMylo() ||
this.DetectArchos())
return true;
if ((this.uagent.search(this.devicePda) > -1) &&
!(this.uagent.search(this.disUpdate) > -1))
return true;
//Detect for certain very old devices with stupid useragent strings.
if ((this.uagent.search(this.manuSamsung1) > -1) ||
(this.uagent.search(this.manuSonyEricsson) > -1) ||
(this.uagent.search(this.manuericsson) > -1) ||
(this.uagent.search(this.svcDocomo) > -1) ||
(this.uagent.search(this.svcKddi) > -1) ||
(this.uagent.search(this.svcVodafone) > -1))
return true;
return false;
},
//*****************************
// For Mobile Web Site Design
//*****************************
//**************************
// The quick way to detect for a tier of devices.
// This method detects for the new generation of
// HTML 5 capable, larger screen tablets.
// Includes iPad, Android (e.g., Xoom), BB Playbook, WebOS, etc.
DetectTierTablet : function() {
if (this.initCompleted || this.isTierTablet)
return this.isTierTablet;
if (this.DetectIpad() ||
this.DetectAndroidTablet() ||
this.DetectBlackBerryTablet() ||
this.DetectFirefoxOSTablet() ||
this.DetectUbuntuTablet() ||
this.DetectWebOSTablet())
return true;
else
return false;
},
//**************************
// The quick way to detect for a tier of devices.
// This method detects for devices which can
// display iPhone-optimized web content.
// Includes iPhone, iPod Touch, Android, Windows Phone 7 and 8, BB10, WebOS, Playstation Vita, etc.
DetectTierIphone : function() {
if (this.initCompleted || this.isTierIphone)
return this.isTierIphone;
if (this.DetectIphoneOrIpod() ||
this.DetectAndroidPhone() ||
this.DetectWindowsPhone() ||
this.DetectBlackBerry10Phone() ||
this.DetectPalmWebOS() ||
this.DetectBada() ||
this.DetectTizen() ||
this.DetectFirefoxOSPhone() ||
this.DetectSailfishPhone() ||
this.DetectUbuntuPhone() ||
this.DetectGamingHandheld())
return true;
//Note: BB10 phone is in the previous paragraph
if (this.DetectBlackBerryWebKit() && this.DetectBlackBerryTouch())
return true;
else
return false;
},
//**************************
// The quick way to detect for a tier of devices.
// This method detects for devices which are likely to be
// capable of viewing CSS content optimized for the iPhone,
// but may not necessarily support JavaScript.
// Excludes all iPhone Tier devices.
DetectTierRichCss : function() {
if (this.initCompleted || this.isTierRichCss)
return this.isTierRichCss;
//Exclude iPhone and Tablet Tiers and e-Ink Kindle devices
if (this.DetectTierIphone() ||
this.DetectKindle() ||
this.DetectTierTablet())
return false;
//Exclude if not mobile
if (!this.DetectMobileQuick())
return false;
//If it's a mobile webkit browser on any other device, it's probably OK.
if (this.DetectWebkit())
return true;
//The following devices are also explicitly ok.
if (this.DetectS60OssBrowser() ||
this.DetectBlackBerryHigh() ||
this.DetectWindowsMobile() ||
(this.uagent.search(this.engineTelecaQ) > -1))
return true;
else
return false;
},
//**************************
// The quick way to detect for a tier of devices.
// This method detects for all other types of phones,
// but excludes the iPhone and RichCSS Tier devices.
// NOTE: This method probably won't work due to poor
// support for JavaScript among other devices.
DetectTierOtherPhones : function() {
if (this.initCompleted || this.isTierGenericMobile)
return this.isTierGenericMobile;
//Exclude iPhone, Rich CSS and Tablet Tiers
if (this.DetectTierIphone() ||
this.DetectTierRichCss() ||
this.DetectTierTablet())
return false;
//Otherwise, if it's mobile, it's OK
if (this.DetectMobileLong())
return true;
else
return false;
}
};
//Initialize the MobileEsp object
MobileEsp.InitDeviceScan();
================================================
FILE: LICENSE
================================================
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
================================================
FILE: MobileESP_UA-Test-Strings/MobileESP UA Test Strings - UA Strings.csv
================================================
UA Type,Device OEM,Device Name,Device Platform,Browser,UA String,Matched Sub-Strings,MobileESP Detection Methods,MobileESP Priority,Comments,Markets Launched,Reference
tablet,Acer,Iconia A500,Andorid ,Android,"Mozilla/5.0 (Linux; U; Android 3.0.1; en-us; A500 Build/HRI66) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13","android, webkit","DetectAndroid(), DetectAndroidTablet(), DetectAndroidWebKit(), DetectWebKit()",High,Launched with Android 3.0 (Honeycomb),International,http://www.zytrax.com/tech/web/mobile_ids.html
mobile,Amazon,Fire,Android,Kindle Silk,"Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Kindle Fire Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1","Android, mobile, webkit","DetectAndroid(), DetectAndroidPhone(), DetectAndroidWebKit(), DetectWebKit()",High,The Kindle Fire Android browser running in normal Android mode. MobileESP ignores the Kindle word here.,International,http://www.labnol.org/software/kindle-user-agent-string/20378/
mobile,Amazon,Fire,Android,Kindle Silk,"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.1.0-80) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=true",silk,DetectAmazonSilk(),High,The US for the Silk browser in accelerated mode on the Amazon Kindle Fire.,International,http://www.labnol.org/software/kindle-user-agent-string/20378/
mobile,Barnes & Noble,Nook Simple Touch,Android,Android,"2.1 NOOK BNRV300---Mozilla/5.0 (Linux; U; Android 2.1; xx-xx; NOOK BNRV300 Build/ERD79) Apple WebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17","android, nook","DetectAndroid(), DetectAndroidPhone(), DetectAndroidWebKit(), DetectWebKit(), DetectNook()",Low,The Simple Touch is black and white but runs Android. ,,
tablet,Barnes & Noble,Nook,Android,Android,nook browser/1.0,nook,"DetectNook(), DetectMobileQuick()",Low,"This was the UA for the Nook 1.0 device. Support is added for detecting the ""Nook"" substring just in case the useragent doesn't report Android or the device is an older eInk one.",International,http://www.zytrax.com/tech/web/mobile_ids.html
tablet,Barnes & Noble,Nook Color,Android,Android,"Mozilla/5.0 (Linux; U; Android 2.3; xx-xx; BNTV250A Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Safari/533.1",android,"DetectAndroid(), DetectAndroidTablet(), DetectAndroidWebKit(), DetectWebKit()",High,"With this UA, the Nook Color reports itself as an Android Tablet. (The Nook Color was the Nook 2.0 device.)",International,http://www.zytrax.com/tech/web/mobile_ids.html
tablet,Google,Nexus 10,Android,Firefox,mozilla/5.0 (android; tablet; rv:37.0) gecko/37.0 firefox/37.0,android,"DetectAndrid(), DetectAndroidTablet()",Medium,"This will detect as a tablet because Firefox doesn't put ""mobile"" in the useragent. ",International,Through direct testing in May 2015.
tablet,Google,Nexus 10,Android,Opera,"mozilla/5.0 (linux; android 5.1.1; nexus 10 build/lmy47v) applewebkit/537.36 (khtml, like gecko) chrome/42.0.2311.107 safari/537.36 opr/29.0.1809.92117","android, webkit","DetectAndroid(), DetectWebKit()",Medium,"No token for ""tablet"". ",International,Through direct testing in May 2015.
tablet,Google,Nexus 10,Android,Opera Mini,opera/9.80 (android; opera mini/8.0.1807/36.1955; u; en) presto/2.12.423 version/12.16,"opera, mini","DetectOperaMobile(), DetectAndroid(), DetectMobileQuick()",Medium,"No token for ""tablet"". Scored 203 out of 555 at www.html5test.com",International,Through direct testing in May 2015.
mobile,HTC,Flyer - Desktop Mode,Android,Android,"mozilla/5.0 (macintosh; u; intel mac os x 10_6_3; htc_flyer_p512; en-us) applewebkit/533.16 (khtml, like gecko) version/5.0 safari/533.16",n/a,"DetectAndroid(), DetectAndroidPhone(), DetectAndroidWebKit(), DetectWebKit()",Low,"As of June 2012, special allowance is made for detecting the HTC Flyer in Desktop mode and identifying it as a phone. ",International,Copied from the HTC browser. Saved in Anthony's personal Gmail.
mobile,HTC,Flyer - Mobile Browsing Mode,Android,Android,"mozilla/5.0 (linux; u; android 2.3.4; en-us; htc_flyer_p512 build/grj22) applewebkit/533.1 (khtml, like gecko) version/4.0 mobile safari/533.1",android,"DetectAndroid(), DetectAndroidPhone(), DetectAndroidWebKit(), DetectWebKit()",Low,"As of June 2012, special allowance is made for detecting the HTC Flyer in Desktop mode and identifying it as a phone.",International,Copied from the HTC browser. Saved in Anthony's personal Gmail.
mobile,HTC,T-Mobile G1,Android,Android,"Mozilla/5.0 (Linux; U; Android 1.1; en-gb; dream) AppleWebKit/525.10+ (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2","Android, mobile, webkit","DetectAndroid(), DetectAndroidPhone(), DetectAndroidWebKit(), DetectWebKit()",High,"The G1 was the first Android device on the US market (first in the world). It launched with Android 1.1, was later OTA updated to 1.5 (Cupcake).",USA,http://www.gtrifonov.com/2010/04/29/google-android-user-agent-strings-3/
mobile,Motorola,DROID RAZR 4G,Android,Android,"Mozilla/5.0 (Linux; U; Android 2.3; xx-xx; DROID RAZR 4G Build/6.5.1-73_DHD-11_M1-29) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1","android, webkit","DetectAndroid(), DetectAndroidPhone(), DetectAndroidWebKit(), DetectWebKit()",Medium,A popular Android device on Verizon. ,USA,http://www.tera-wurfl.com/explore/?action=wurfl_id&id=motorola_droid_razr_ver1
tablet,Motorola,Xoom,Android,Android,"Mozilla/5.0 (Linux; U; Android 3.0.1; en-us; Xoom Build/HWI69) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13",android,"DetectAndroid(), DetectAndroidTablet(), DetectAndroidWebKit(), DetectWebKit()",High,Launched with Android 3.0 (Honeycomb). The string varied slightly by culture/language and build.,International,http://www.zytrax.com/tech/web/mobile_ids.html
phone,Motorola,Moto X (2013),Android,Firefox,mozilla/5.0 (android; mobile; rv:37.0) gecko/37.0 firefox/37.0,"android, mobile","DetectAndroid(), DetectAndroidPhone()",Medium,,International,Through direct testing in May 2015.
phone,Motorola,Moto X (2013),Android,Opera,"mozilla/5.0 (linux; android 4.4.4; xt1053 build/kxa21.12-l1.29.1) applewebkit/537.36 (khtml, like gecko) chrome/42.0.2311.107 mobile safari/537.36 opr/29.0.1809.92117","android, mobile, webkit","DetectAndroid(), DetectAndroidPhone(), DetectWebKit()",Medium,"The new WebKit-based browser is more capable, so we don't count it as Opera Mobile.",International,Through direct testing in May 2015.
phone,Motorola,Moto X (2013),Android,Opera Mini,opera/9.80 (android; opera mini/8.0.1807/36.1955; u; en) presto/2.12.423 version/12.16,"opera, mini","DetectOperaMobile(), DetectAndroid(), DetectMobileQuick()",Medium,"No token for ""mobile."" ",International,Through direct testing in May 2015.
mobile,Samsung,Galaxy S 3,Android,Android,"mozilla/5.0 (linux; u; android 4.0.4; en-us; gt-i9300 build/imm76d) applewebkit/534.30 (khtml, like gecko) version/4.0 mobile safari/534.30","Android, mobile, webkit","DetectAndroid(), DetectAndroidPhone(), DetectAndroidWebKit(), DetectWebKit()",High,Samsung's 2012 flagship Android device. Sold worldwide.,International,
tablet,Sony,Tablet P,Android,Android,"Mozilla/5.0 (Linux; U; Android 3.2; de-de; Sony Tablet P Build/THMD01900) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13",android,"DetectAndroid(), DetectAndroidTablet(), DetectAndroidWebKit(), DetectWebKit()",High,A dual-screen Android tablet.,International,http://www.zytrax.com/tech/web/mobile_ids.html
tablet,Sony,Tablet S,Android,Android,"Mozilla/5.0 (Linux; U; Android 3.2; en-gb; Sony Tablet S Build/THMD01900) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13",android,"DetectAndroid(), DetectAndroidTablet(), DetectAndroidWebKit(), DetectWebKit()",High,"A 9.4"" Android tablet.",International,http://www.zytrax.com/tech/web/mobile_ids.html
tablet,Toshiba,AT100-100,Android,Android,"Mozilla/5.0 (Linux; U; Android 3.1; de-de; AT100 Build/HMJ37) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13",Android,"DetectAndroid(), DetectAndroidTablet(), DetectAndroidWebKit(), DetectWebKit()",High,"A 10.1"" Android tablet",International,http://www.zytrax.com/tech/web/mobile_ids.html
mobile,Samsung,GT-S5253,Bada,Dolfin,SAMSUNG-GT-S5253/1.0 Bada/1.0 AppleWebKit/533.1 Dolfin/2.0 Mobile NexPlayer/3.0 SMM-MMS/1.2.0 profile/MIDP-2.1 configuration/CLDC-1.1 OPN-B,"bada, mobile, midp, webkit","DetectBada(), DetectWebKit(), DetectMidpCapable()",Low,Bada is Samsung's proprietary Linux-based smartphone OS for non-USA markets. The Dolfin browser is quite good. This device is in the Bada 1.0 series.,International,http://www.tera-wurfl.com/explore/?action=wurfl_id&id=samsung_gt_s5253_ver1
mobile,BlackBerry,9380 Curve Touch,BlackBerry,BlackBerry,"BlackBerry; U; BlackBerry 9380; xx-xx) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.0.0.557 Mobile Safari/534.11+",blackberry 938,"DetectBlackBerry(), DetectBlackBerryTouch(), DetectBlackWebKit()",Low,"A touchscreen device for international markets with a large, iPhone-like screen.",International,http://www.tera-wurfl.com/explore/?action=wurfl_id&id=blackberry9380_ver1
mobile,BlackBerry,Porsche Design P’9981,BlackBerry,BlackBerry,"BlackBerry; U; BlackBerry 9981; xx-xx) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.0.0.579 Mobile Safari/534.11+","blackberry, webkit","DetectBlackBerry(), DetectBlackBerryTouch(), DetectBlackWebKit()",Low,This device is in the Bold Touch series. ,International,http://www.tera-wurfl.com/explore/?action=wurfl_id&id=blackberry9981_ver1
mobile,BlackBerry,Style 9670,BlackBerry,BlackBerry,"BlackBerry; U; BlackBerry 9670; xx-xx) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.226 Mobile Safari/534.1+","blackberry, webkit","DetectBlackBerry(), DetectBlackWebKit()",Low,The device was launched on Sprint in late 2010.,USA,http://www.tera-wurfl.com/explore/?action=wurfl_id&id=blackberry_9670_ver1
mobile ,BlackBerry,Tour 9630,BlackBerry,BlackBerry,BlackBerry9630/4.7.1.40 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/126,blackberry96,"DetectBlackBerry(), DetectBlackHigh()",Low,"This device had a browser which could display CSS reasonably well, but didn't have much JS skills. High profile in late 2008.",International,http://www.tera-wurfl.com/explore/?action=wurfl_id&id=blackberry9630_ver1
mobile,BlackBerry ,Bold (multiple models),BlackBerry,BlackBerry,BlackBerry9700/5.0.0.207 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/175,blackberry97,"DetectBlackBerry(), DetectBlackHigh()",Medium,"The Bold line is one of RIM's most popular models, with many variants. Note that touchscreen versions of the bold also register like this (as a non-touch device) due to the small screen. iPhone-style UIs would not work well.",International,http://www.tera-wurfl.com/explore/?action=wurfl_id&id=blackberry9700_ver1
mobile,BlackBerry,Curve 2 8900,BlackBerry ,BlackBerry,BlackBerry8900/4.6.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/100,blackberry89,"DetectBlackBerry(), DetectBlackHigh()",Low,The device was high profile in the US esp. in 2008.,International,http://www.tera-wurfl.com/explore/?action=wurfl_id&id=blackberry8900_ver1
mobile,BlackBerry,BB10 Developer Phone,BlackBerry 10,BlackBerry,"Mozilla/5.0 (BB10; touch) AppleWebKit/537.3+ (KHTML, like Gecko) Version/10.0.9.388 Mobile Safari/537.3+","bb10, webkit","DetectBlackBerry(), DetectBlackBerry10Phone(), DetectWebKit(), DetectIphoneTier(), DetectSmartphone()",Low,This is a test phone. The real devices going on sale will be High Priority.,International,http://devblog.blackberry.com/2012/08/blackberry-10-user-agent-string/
mobile,BlackBerry,Pearl (8100),BlackBerry 4.2,BlackBerry,BlackBerry8100/4.5.0.108 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/214,blackberry,"DetectBlackBerry(), DetectBlackBerryLow()",Low,The first consumer-oriented BlackBerry device. Was a hit seller.,International,http://www.mobilerated.com/rim-blackberry-8100-pearl-specifications.html
mobile,BlackBerry,Storm 2,BlackBerry OS,BlackBerry,BlackBerry9550/5.0.0.320 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/105,blackberry95,"DetectBlackBerry(), DetectBlackBerryTouch(), DetectBlackBerryHigh()",High,"Lead the flagship all-touch line of devices, esp. Verizon, Nov. 2009.",USA & International,http://www.tera-wurfl.com/explore/?action=wurfl_id&id=blackberry9550_ver1
mobile,BlackBerry,Torch (9800),BlackBerry OS,BlackBerry,"BlackBerry; U; BlackBerry 9800; xx-xx) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.135 Mobile Safari/534.1+",blackberry 98,"DetectBlackBerry(), DetectBlackBerryTouch(), DetectBlackWebKit()",High,Lead the touch BlackBerry device line at AT&T.,USA & International,http://www.tera-wurfl.com/explore/?action=wurfl_id&id=blackberry9800_ver1
mobile,BlackBerry,Playbook,BlackBerry OS (QNX),BlackBerry,"Mozilla/5.0 (PlayBook; U; RIM Tablet OS 2.1.0; en-US) AppleWebKit/536.2+ (KHTML, like Gecko) Version/7.2.1.0 Safari/536.2+'",playbook,DetectBlackBerryTablet(),Medium,RIM's flagship tablet.,USA & International,http://www.tera-wurfl.com/explore/?action=wurfl_id&id=rim_playbook_android_ver1
mobile,HTC,Freestyle (F5151),Brew,Obigo,"HTC-F5151/1.0 Mozilla/5.0 (BMP; U; en) AppleWebKit/530.8 (KHTML, like Gecko) OBIGO/W10 Safari/530.8",obigo,"DetectWebKit() , DetectMobileQuick()",Low,"This device is listed because it's a small but modern touchscreen feature phone. The modern Obigo W10 browser is based on WebKit, so it more capable than legacy Teleca or Obigo browsers.",International,http://developer.att.com/developer/device_detailSpec.jsp?id=6.3_v1_10800390
mobile,Pantech,Link II ,Brew,Netfront,PantechP5000/JTUS06272011 BMP/1.0.2 DeviceId/141025 NetFront/4.1 OMC/1.5.3 Profile/MIDP-2.1 Configuration/CLDC-1.1,"midp, netfront","DetectMobileQuick(), DetectMidpCapable()",Low,"A feature phone on AT&T in 2012. Available worldwide, too. ",International,
desktop,Apple,Mac,Desktop,Safari,"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_5; en-us) AppleWebKit/525.18 (KHTML, like Gecko) Version/ 3.1.2 Safari/525.20.1",n/a,Unsupported,High,"A desktop or laptop running Mac OS. As with all ""desktop"" devices, should not be detected by MobileESP.",International,http://www.zytrax.com/tech/web/mobile_ids.html
game,Nintendo,3DS,Embedded,Opera,Mozilla/5.0 (Nintendo 3DS; U; ; de) Version/1.7455.EU,nintendo,"DetectNintendo(), DetectGameConsole()",Low,Anonther Nintendo handheld gaming device.,International,http://www.botsvsbrowsers.com/details/747492/index.html
game,Nintendo,DS,Embedded,Opera,Opera/9.00 (Nintendo DS; U; ; 1309-9; en),nintendo,"DetectNintendo(), DetectGameConsole()",Medium,There are tons of useragents for the Nintendo DS. This appears to be a reasonable choice for tracking. ,International,http://www.botsvsbrowsers.com/details/341766/index.html
game,Nintendo,DSi,Embedded,Opera,Nintendo DSi; Opera Mini/5.1.21965/20.2513; U; en,"nintendo, opera mini","DetectNintendo(), DetectGameConsole(), DetectOperaMobile()",Low,Anonther Nintendo handheld gaming device.,International,http://www.botsvsbrowsers.com/details/728961/index.html
game,Nintendo,Wii,Embedded,Opera,Opera/9.30 (Nintendo Wii; U; ; 2047-7; en),"nintendo, wii","DetectNintendo(), DetectGameConsole()",Medium,"Not high priority, but it is currently supported. Technically, this belongs in a TV Tier.",International,http://www.zytrax.com/tech/web/mobile_ids.html
mobile,Cricket,A410,Feature Phone,Brew,Cricket-A410/1.0 Polaris/v6.17,n/a,Unsupported,Low - LMI,This Brew device was launched on the Cricket network in the US. Little is known about device. ,USA,http://www.zytrax.com/tech/web/mobile_ids.html
mobile,Danger,Hiptop,Feature Phone,Danger,Mozilla/5.0 (Danger hiptop 3.4; U; AvantGo 3.2),danger hiptop,DetectDangerHiptop(),Low,A popular feature phone around 2006.,USA,http://www.zytrax.com/tech/web/mobile_ids.html
mobile,LG,enV3 (VX9200),Feature Phone,Teleca,Mozilla/5.0 (compatible; Teleca Q7; Brew 3.1.5; U; xx-xx) 320X240 LGE VX9200,"brew, teleca q","DetectMobileQuick(), DetectBrew(), DetectRichCss()",Low,"A popular feature phone, esp. on Verizon.",USA & International,http://www.tera-wurfl.com/explore/?action=wurfl_id&id=lg_vx9200_ver1
mobile,LG,Chocolate (KG-800),Feature Phone,Teleca-Obigo,LG-KG800/V10e Obigo/WAP2.0 MIDP-2.0/CLDC-1.1,midp,DetectMidpCapable(),Low,A popular feature phone worldwide around 2008.,International,http://www.mobile-phone-specs.com/model/lg_kg800_ver1/
mobile,Motorla,RAZR2 V9m,Feature Phone,Up,MOT-V9mm/00.62 UP.Browser/6.2.3.4.c.1.123 (GUI) MMP/2.0,up.browser,DetectMobileQuick(),Low,One of many devices using the Up Browser. ,International,http://www.zytrax.com/tech/web/mobile_ids.html
mobile,Samsung,A737,Feature Phone,Brew,Mozilla/4.1 (U; BREW 3.1.5; en-US; Teleca/Q05A/INT),brew,DetectBrewDevice(),Medium,Should test positive for being a Brew device. It might work with a real phone due to the Accept properties (WML). Failed on 3/25/12.,USA,http://www.zytrax.com/tech/web/mobile_ids.html
mobile,Samsung,SPH-A620 VGA1000,Feature Phone,Obigo,Mozilla/4.0 (compatible; MSIE 6.0; j2me) ReqwirelessWeb/3.5,n/a,Unsupported,L - LMI,Not worth the effort to add support for this one obsolete device. Sold at Sprint.,USA,http://www.zytrax.com/tech/web/mobile_ids.html
mobile,Siemens,S55,Feature Phone,Embedded,ReqwirelessWeb/3.2 S55,n/a,Unsupported,L - LMP-D,A very old feature phone with a very small screen.,International,http://www.zytrax.com/tech/web/mobile_ids.html
mobile,Various,Various,Feature Phones,Opera Mini,Opera/9.80 (J2ME/MIDP; Opera Mini/4.2.13221/25.623; U; en) Presto/2.5.25 Version/10.54,opera mini,DetectOperaMobile(),Medium,"Thought to be installed on various feature phones, including BlackBerries.",International,http://www.zytrax.com/tech/web/browser_ids.htm
mobile,Various,Various,Feature Phones,Opera Mini,Opera/9.80 (J2ME/MIDP; Opera Mini/5.1.21214/19.916; U; en) Presto/2.5.25,opera mini,DetectOperaMobile(),Medium,Thought to be installed on various feature phones.,International,http://www.zytrax.com/tech/web/browser_ids.htm
mobile,Various,Various,Feature Phones,Opera Mini,Opera/9.80 (J2ME/MIDP; Opera Mini/5.0.16823/1428; U; en) Presto/2.2.0,opera mini,DetectOperaMobile(),Medium,Thought to be installed on various feature phones.,International,http://www.zytrax.com/tech/web/browser_ids.htm
TV,Amazon,Fire TV,Fire OS,WebView,"Mozilla/5.0 (Linux; Android 4.2.2; AFTB Build/JDQ39) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.173 Mobile Safari/537.22 cordova-amazon-fireos/3.4.0 AmazonWebAppPlatform/3.4.0;2.0",amazonwebappplatform,"DetectFireTV()
DetectSmartTV()",Low,"Amazon's Fire TV doesn't have a standalone browser. Instead, apps can use a WebView to display HTML content. ",International,https://developer.amazon.com/public/solutions/devices/fire-tv/docs/user-agent-strings
mobile,Various,Various,Firefox OS,Firefox,Mozilla/5.0 (Mobile; rv:26.0) Gecko/26.0 Firefox/26.0,"firefox, mobile","DetectFirefoxOS(), DetectFirefoxOSPhone(), DetectTierIphone(), DetectSmartphone(), DetectMobileQuick()",Low,Potential new up and coming mobile OS. Need to exclude Android and iOS from check to disambiguate. ,International,https://developer.mozilla.org/en-US/docs/Web/HTTP/Gecko_user_agent_string_reference
tablet,Various,Various,Firefox OS,Firefox,Mozilla/5.0 (Tablet; rv:26.0) Gecko/26.0 Firefox/26.0,"firefox, tablet","DetectFirefoxOS(), DetectFirefoxOSTablet()",Low,Potential new up and coming mobile OS. ,International,https://developer.mozilla.org/en-US/docs/Web/HTTP/Gecko_user_agent_string_reference
tablet,Apple,iPad,iOS,Maxthon,"mozilla/5.0 (ipad; cpu os 7_0_2 llike mac os x) applewebkit/537.51.1 (khtml, like gecko) mobile/11a501a ","ipad, mobile, webkit","DetectTierTablet(), DetectWebkit(), DetectIpad(), DetectIos()",High,A popular browser in China now available worldwide. The Maxthon browser is available on iOS and Android devices. ,International,Screenshot from an iPad in October 2013.
tablet,Apple,iPad,iOS,Opera Coast,"Mozilla/5.0 (iPad; CPU OS 7_0_6 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Coast/2.0.5.71150 Mobile/11B651 Safari/7534.48.3","ipad, webkit","DetectTierTablet(), DetectWebkit(), DetectIpad(), DetectIos()",Low,"Because Opera Coast uses WebKit and tags the agent with ""iPad"", it will detect as if it's the default Apple browser. Opera Coast's iPhone browser similarly detects as iPhone. ",International,https://udger.com/resources/ua-list/browser-detail?browser=Coast
phone,Apple,iPhone,iOS,Opera Mini,"mozilla/5.0 (iphone; cpu iphone os 8_3 like mac os x) applewebkit/600.1.4 (khtml, like gecko) opios/10.0.1.90729 mobile/12f70 safari/9537.53","iphone, webkit","DetectIphone(), DetectIphoneOrIpod(), DetectIos(), DetectWebKit()",Low,"Because Opera Mini now has iPhone and WebKit tokens in the browser, it will be detected the same as the iPhone's native browser. ",International,Through direct testing in May 2015.
mobile,Apple,iPhone,iOS,Safari Mobile,"Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7","iphone, webkit","DetectIphone(), DetectIphoneOrIpod(), DetectIos(), DetectWebKit()",High,iOS v 4 on iPhone,International,http://www.zytrax.com/tech/web/browser_ids.htm
mobile,Apple,"iPod Touch
(Generation: Fall 2012)",iOS,Safari Mobile,"mozilla/5.0 (ipod; cpu iphone os 6_0 like mac os x) applewebkit/536.26 (khtml, like gecko) version/6.0 mobile/10a406 safari/8536.25","ipod, iphone, webkit","DetectIpod(), DetectIphoneOrIpod(), DetectIos(), DetectWebKit()",High,iOS v 6 on iPod Touch (Device launched Fall 2012),International,"UA string captured on a device in the Apple store, Oct. 2012."
tablet,Apple,iPad,iOS,Safari Mobile,"Mozilla/5.0 (iPad; U; CPU OS 4_3_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8G4 Safari/6533.18.5","ipad, webkit","DetectIpad(), DetectWebKit()",High,The Apple iPad running iOS version 4.,International,http://www.zytrax.com/tech/web/mobile_ids.html
mobile,Apple,iPod Touch,iOS ,Safari Mobile,"Mozilla/5.0 (iPod; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7","ipod, iphone, webkit","DetectIpod(), DetectIphoneOrIpod(), DetectIos(), DetectWebKit()",High,iOS v 4 on iPod Touch,International,http://www.zytrax.com/tech/web/browser_ids.htm
mobile,Amazon,Kindle ,Kindle,Kindle (Monochrome),"Mozilla/5.0 (Linux; U; en-US) AppleWebKit/528.5+ (KHTML, like Gecko, Safari/528.5+) Version/4.0 Kindle/3.0 (screen 600×800; rotate)","kindle, webkit","DetectKindle(), DetectWebKit()",High,For the eInk monochrome devices only. ,International,http://www.labnol.org/software/kindle-user-agent-string/20378/
mobile,Archos,605 WiFi,Linux,Opera,opera/9.02 (linux armv5tejl; u; archos; gogi; a605; en),archos,"DetectArchos(), DetectMobileQuick(), DetectTierOtherPhones()",n/a,An older 4.3 inch video & music player with an embedded browser. Released about 2007. ,International,"Screenshot from a friend who owns the device. Info & specs:
http://www.mobiletechreview.com/mediaplayers/Archos-605-wifi.htm"
mobile,Archos,7 Internet Media Tablet,Linux,Opera,opera/9.02 (linux armv71; u; archos; gogi; g61; version 1.7.22 (wmdrmpd: 10.1) ; en),archos,"DetectArchos(), DetectMobileQuick(), DetectTierOtherPhones()",n/a,An older 7 inch portable video & music player with an embedded browser. Released about 2009. ,International,"Screenshot from a friend who owns the device. Info & specs:
http://www.mobiletechreview.com/mediaplayers/Archos-7.htm"
mobile,Garmin ,Nüvifone G60,Linux,WebKit-based,"Mozilla/5.0 (Linux; U; arm; xx-xx, Nuvifone) AppleWebKit/523.13 (KHTML, like Gecko) Version/3.0 Mobile Safari/419.3 Qt Qtopia Iris/1.1.2","mobile, webkit","DetectGarminNuvifone(), DetectTierRichCss()",Low,"Because of its capable WebKit-based browser, this device was singled out for addition to the code. Released to AT&T in late 2009. Other Garmin phones based on Android ought to self-report as Android devices.",USA,http://www.tera-wurfl.com/explore/?action=wurfl_id&id=garmin_nuviphone_ver1
mobile,Sony,Mylo COM 1,Linux,Opera,Opera/8.02 (Qt embedded; Linux armv4ll; U) [ja] SONY/COM1,sony/com,"DetectSonyMylo(), DetectMobileLong()",Low,A poorly selling Internet tablet around 2007.,,http://www.osnews.com/thread?186230
mobile,Sony,Mylo COM 2,Linux,Unknown (Netfront?),"Mozilla/5.0 (Linux, Sony/COM2/1.01 [en]; like Gecko/2007) Firefox/2",sony/com,"DetectSonyMylo(), DetectMobileLong()",Low,A poorly selling Internet tablet around 2007.,International,http://www.myuseragentstring.com/useragents/sony/sony_mylo_ver1/
mobile,Nokia,N800,Maemo,Fennec (Mobile Firefox),Mozilla/5.0 (X11; U; Linux armv61; en-US; rv:1.9.1b2pre) Gecko/20081015 Fennec/1.0a1,n/a,Unsupported,Low - LMP-B,"Fennec was a beta on Maemo, more of an experiment.",International,http://www.zytrax.com/tech/web/browser_ids.htm
mobile,Nokia,N800,Maemo,Firefox,Mozilla/5.0 (X11; U; Linux armv6l; en-US; rv:1.9a6pre) Gecko/20070810 Firefox/3.0a1 Tablet browser 0.1.16 RX-34_2007SE_4.2007.38-2,"linux, tablet",DetectMaemoTablet(),Low,"On the Nokia N800, may have been the default browser.",International,http://www.zytrax.com/tech/web/mobile_ids.html
mobile,Nokia,N900,Maemo,Firefox,Mozilla/5.0 (X11; U; Linux armv7l; en-GB; rv:1.9.2b6pre) Gecko/20100318 Firefox/3.5 Maemo Browser 1.7.4.7 RX-51 N900,maemo,DetectMaemoTablet(),Low,"Nokia's only Maemo phone. It was high visibility around 2010. Although the browser was decently capable, it's not worth putting in exception code to move it to the RichCSS Tier.",International,http://www.developer.nokia.com/Community/Wiki/User-Agent_headers_for_Nokia_devices
mobile,Nokia,N800,Maemo,Links,Links (2.1pre31; Linux 2.6.21-omap1 armv6l; x),n/a,Unsupported,L - LMP-B,UA for the Links browser for Nokia's Maemo platform.,International,http://www.zytrax.com/tech/web/mobile_ids.html
mobile,Nokia,N800,Maemo,Midori,"Mozilla/5.0 (X11; U; Linux armv6l; en-us) AppleWebKit/528.5+ (KHTML, like Gecko, Safari/528.5+) midori",n/a,Unsupported,L - LMP-B,UA for the Midori browser for Maemo. Midori was released on a few other small devices. (Wikipedia),International,http://www.zytrax.com/tech/web/mobile_ids.html
mobile,Nokia,N800,Maemo,Minimo,Mozilla/5.0 (X11; U; Linux armv6l; rv 1.8.1.5pre) Gecko/20070619 Minimo/0.020,n/a,Unsupported,Low - LMP-B,This was basically an experimental version of Firefox that was only minimally released for the Nokia N800. Predates Fennec.,International,http://www.zytrax.com/tech/web/mobile_ids.html
mobile,Nokia,N800,Maemo,Prism,Mozilla/5.0 (X11; U; Linux armv6l; en-US; rv: 1.9.1a2pre) Gecko/20080813221937 Prism/0.9.1,n/a,Unsupported,L - LMP-B,UA for the Links browser for Nokia's Maemo platform.,International,http://www.zytrax.com/tech/web/mobile_ids.html
mobile,Nokia,N800,Maemo,Tear,"Mozilla/5.0 (X11; U; Linux armv6l; en-us) AppleWebKit/528.5+ (KHTML, like Gecko, Safari/528.5+) tear",n/a,Unsupported,L - LMP-B,Beta for the Tear browser for Nokia's Maemo platform.,International,http://www.zytrax.com/tech/web/mobile_ids.html
mobile,Nokia,"N9
N950",Meego,Meego (Nokia),"Mozilla/5.0 (MeeGo; NokiaN9) AppleWebKit/534.13 (KHTML, like Gecko) NokiaBrowser/8.5.0 Mobile Safari/534.13","meego, webkit, mobile","DetectMeego(), DetectMobileQuick(), DetectWebkit(), DetectTierRichCss()",Low,A device with limited sales and a deadend mobile OS. Both this device and the Nokia N950 shared the same useragent string. ,International,http://www.developer.nokia.com/Resources/Library/Web/#!nokia-browsers/nokia-browser-85-for-meego-12-harmattan/user-agent.html
mobile,Nokia,"N9
N950",Meego,Opera,Opera/9.80 (Linux armv7l; Opera Mobi/1; MeeGo) Presto/2.11.355 Version/12.10,"meego, webkit, mobile","DetectMeego(), DetectMobileQuick(), DetectWebkit(), DetectTierRichCss()",Low,A device with limited sales and a deadend mobile OS. Both this device and the Nokia N950 shared the same useragent string. ,International,http://www.developer.nokia.com/Resources/Library/Web/#!nokia-browsers/nokia-browser-85-for-meego-12-harmattan/user-agent.html
mobile,Various,Various,Mobile Devices,Bolt,"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; BOLT/2.800) AppleWebKit/534.6 (KHTML, like Gecko) Version/5.0 Safari/534.6.3",n/a,Unsupported,Low - LMP-B,The Bolt mobile browser. Not sure if this is a generic UA for installed devices or also when white labeled.,International,http://www.zytrax.com/tech/web/mobile_ids.html#bolt
mobile,Palm,Centro,PalmOS,Blazer,Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Palmsource/Palm-D062; Blazer/4.5) 16;320X320,palm,DetectPalmWebOS(),Low,"Released in late 2007, this was the last significant PalmOS consumer device. It was a popular device in 2008. ",USA,http://www.tera-wurfl.com/explore/?action=wurfl_id&id=palm_centro_ver1
mobile,Palm,Various,PalmOS,Skysurf,Mozilla/4.74 [en] (X11; I; ProxiNet),n/a,Unsupported,L - LMP-B,"An archaic browser on a dead platform: ""Zero Grvaity's Skysurf, running under PalmOS 3.0""",International,http://www.zytrax.com/tech/web/mobile_ids.html
tablet,BlackBerry,PlayBook,PlayBook,PlayBook,"Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.1.0.7 Safari/534.11+",playbook,DetectBlackBerryTablet(),High,"The BlackBerry PlayBook tablet, launched 2011.",International,Sent by a MobileESP user based on his web site access logs
mobile,Sony,Playstation,Playstation,Playstation,Mozilla/5.0 (PLAYSTATION 3; 1.00),playstation,"DetectSonyPlaystation(), DetectGameConsole()",Medium,A Sony Playstation gaming console.,International,http://www.zytrax.com/tech/web/mobile_ids.html
mobile,Sony,Playstation,Playstation,Playstation,"Mozilla/5.0 (PLAYSTATION 3 4.11) AppleWebKit/531.22.8 (KHTML, like Gecko)",playstation,"DetectSonyPlaystation(), DetectGameConsole(), DetectWebKit()",Low,Another version of a useragent for Sony Playstation gaming console.,International,http://www.hvz.baden-wuerttemberg.de/analysehvz/agent_201203.html
mobile,Sony,Playstation Portable,Playstation,Playstation,Mozilla/4.0 (PSP (PlayStation Portable); 2.00),playstation,"DetectSonyPlaystation(), DetectGameConsole()",Low,A handheld gaming console.,International,http://www.hvz.baden-wuerttemberg.de/analysehvz/agent_201203.html
mobile,Sony,Playstation Vita,Playstation,Playstation (Webkit),"Mozilla/5.0 (Playstation Vita 2.02) AppleWebKit/536.26 (KHTML, like Gecko) Silk/3.2","playstation, webkit","DetectSonyPlaystation(), DetectWebKit(), DetectGameConsole(), DetectPlayStationHandheld(), DetectTierIphone()",Medium,A handheld gaming console with an iPhone-class browser.,International,http://community.eu.playstation.com/t5/PS-Vita-General-Discussion/PS-vita-web-browser-a-few-details/td-p/14477729
mobile,bSquare,bSquare,PocketPC,MS IE Mobile,Mozilla/4.0 (compatible; MSIE 5.5; Windows NT) (compatible; MSIE 5.5; Windows NT),n/a,Unsupported,Low - LMP - D,bSquare never sold their devices to consumers under their own label. This was the UA on reference hardware during early testing. ,None,http://www.zytrax.com/tech/web/mobile_ids.html
mobile,HTC,Touch Pro,PocketPC,MS IE Mobile,XV6850 Opera/9.50 (Windows NT 5.1; U; en),n/a,Unsupported,Low - LMI,Not worth the effort to add support for this one obsolete device. The only unique element is the device ID (XV6850).,USA,http://www.zytrax.com/tech/web/mobile_ids.html
mobile,Sharp,Zarus SL-C750,PocketPC,MS IE Mobile,Mozilla/4.0 (compatible; MSIE 5.0; Linux 2.4.18-rmk7-pxa3-embedix armv5tel; 480x640) Opera 6.0 [en],n/a,Unsupported,L - LMI,An old PocketPC-based Zarus PDA. May have been marketed outside of Japan.,Japan,http://www.zytrax.com/tech/web/mobile_ids.html
mobile,Various,Various,PocketPC,MS IE Mobile,Mozilla/2.0 (compatible; MSIE 3.02; Windows CE; 240x320),windows ce,DetectWindowsMobile(),Low - OD,,International,http://www.zytrax.com/tech/web/browser_ids.htm
mobile,Various,Various,PocketPC,Opera Mobile,Mozilla/4.0 (compatible; MSIE 6.0; Windows CE; PPC; 480x640) Opera 8.60 [en],"opera, windows ce","DetectOperaMobile(), DetectWindowsMobile()",Medium,Opera Mobile on Windows PocketPC devices.,International,http://www.zytrax.com/tech/web/browser_ids.htm
TV,ROku,various,Roku,WebView,Roku/DVP-5.2 (025.02E03197A),roku,"DetectRokuTV()
DetectSmartTV()",Low,"Roku doesn't have a standalone browser. Instead, apps can use a WebView to display HTML content. ",International,https://udger.com/resources/ua-list/device-detail?device=Smart+TV
mobile,Nokia,Nokia X3-02,S40,WAP Browser,Mozilla/5.0 (Series40; NokiaX3-02/06.00; Profile/MIDP-2.1 Configuration/CLDC-1.1) Gecko/20100401 S40OviBrowser/1.5.0.34.11,midp,DetectMobileQuick(),Medium,"Nokia still sells tons of S40-based feature phones around the world. Especially in developing countries, these devices are often used for accessing web sites. ",International,http://www.developer.nokia.com/Community/Wiki/User-Agent_headers_for_Nokia_devices
mobile,Jolla,Various,Sailfish,SailfishBrowser,Mozilla/5.0 (Maemo; Linux; U; Jolla; Sailfish; Mobile; rv:31.0) Gecko/31.0 Firefox/31.0 SailfishBrowser/1.0,"sailfish, mobile","DetectSailfish(), DetectSailfishPhone(), DetectTierIphone(), DetectSmartphone(), DetectMobileQuick()",Low,Potential new up and coming mobile OS.,International,https://together.jolla.com/question/81498/webservice-request-from-android-app-seems-to-be-overridden-with-user-agent-string-phandroidappl/
tablet,Jolla,Various,Sailfish,SailfishBrowser,None available yet,TBD,TBD,Low,Potential new up and coming mobile OS. This Tablet method is speculative right now pending confirmation of useragent. ,International,
mobile,Nokia,Various,Symbian,Opera Mobile,Opera/9.80 (S60; SymbOS; Opera Mobi/499; U; ru) Presto/2.4.18 Version/10.00,"opera mobi, symbos","DetectOperaMobile(), DetectSymbianOS()",Medium,Opera Mobile 10.0 running on Nokia Symbian S60 devices.,International,http://www.zytrax.com/tech/web/browser_ids.htm
mobile,Nokia,Nokia 5800 XpressMusic,Symbian,OSS Browser,"Mozilla/5.0 (SymbianOS/9.4; U; Series60/5.0 Nokia5800d-1/21.0.025; Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML, like Gecko) Safari/413","symbian, series60, webkit","DetectS60OssBrowser()
DetectSymbianOS(), DetectWebKit(), DetectTierRichCss()",Low,The OSS WebKit browser shipping on the new touch-based Nokia 5800 running S60 5th Edition.,International,http://www.developer.nokia.com/Community/Wiki/User-Agent_headers_for_Nokia_devices
mobile,Nokia,Nokia 701 (Belle Refresh),Symbian,OSS Browser,"Mozilla/5.0 (Symbian/3; Series60/5.3 Nokia701/111.020.0307; Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/533.4 (KHTML, like Gecko) NokiaBrowser/7.4.1.14 Mobile Safari/533.4 3gpp-gba","symbian, series60, webkit","DetectS60OssBrowser()
DetectSymbianOS(), DetectWebKit(), DetectTierRichCss()",Medium,"The OSS WebKit browser shipping on the 2010 Nokia 701 running Symbian^3 (the open sourced version of Symbian). ""Belle"" OS update.",International,http://www.developer.nokia.com/Community/Wiki/User-Agent_headers_for_Nokia_devices
mobile,Nokia,Nokia N8 (Anna Refresh),Symbian,OSS Browser,"Mozilla/5.0 (Symbian/3; Series60/5.2 NokiaN8-00/012.002; Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/533.4 (KHTML, like Gecko) NokiaBrowser/7.3.0 Mobile Safari/533.4 3gpp-gba","symbian, series60, webkit","DetectS60OssBrowser()
DetectSymbianOS(), DetectWebKit(), DetectTierRichCss()",Medium,"The OSS WebKit browser shipping on the 2010 flagship Nokia N8 running Symbian^3 (the open sourced version of Symbian). ""Anna"" OS update.",International,http://www.developer.nokia.com/Community/Wiki/User-Agent_headers_for_Nokia_devices
mobile,Nokia,S60 r3 Newer Devices,Symbian,OSS Browser,"Mozilla/5.0 (SymbianOS/9.1; U; [en]; Series60/3.0 NokiaE60/4.06.0) AppleWebKit/413 (KHTML, like Gecko) Safari/413","symbian, series60","DetectS60OssBrowser()
DetectSymbianOS(), DetectTierRichCss()",Low,"The ""new"" WebKit-based Open Source browser on later batches of Symbian r3 devices. 2006-07 era, probably. ",International,http://www.developer.nokia.com/Community/Wiki/User-Agent_headers_for_Nokia_devices
mobile,Nokia,S60 r3 Older Devices,Symbian,OSS Browser,"Mozilla/5.0 (SymbianOS/9.1; U; [en-us]) AppleWebKit/413 (KHTML, like Gecko) Safari/413",symbian,"DetectS60OssBrowser()
DetectSymbianOS(), DetectTierRichCss()",Low,"The ""new"" WebKit-based Open Source browser on the first batch or so of Symbian r3 devices. 2006-07 era, probably. ",International,http://www.developer.nokia.com/Community/Wiki/User-Agent_headers_for_Nokia_devices
mobile,Nokia,Nokia N73 (S60 r3),Symbian,S60 WAP Browser,NokiaN73-2/3.0-630.0.2 Series60/3.0 Profile/MIDP-2.0 Configuration/CLDC-1.1,symbian,DetectSymbianOS(),Low,This was for the original proprietary S60 WAP browser that was NOT based on WebKit. It shipped on many devices simultaneously with the newer OSS browser in S60 r3 before finally being killed. ,International,http://www.developer.nokia.com/Community/Wiki/User-Agent_headers_for_Nokia_devices
mobile,Various,Various,Symbian,Opera Mini,Opera/9.80 (Series 60; Opera Mini/6.1.26266/26.1069; U; en) Presto/2.8.119 Version/10.54,opera mini,DetectOperaMobile(),Medium,Version of Opera Mini for such Symbian devices as the Nokia E63.,International,http://www.handsetdetection.com/properties/tags/Nokia/E63/Opera%20Mini/6.1.26266
mobile,Sony Ericsson,W960i,Symbian UIQ,Opera Mobile,SonyEricssonW960i/R100 Mozilla/4.0 (compatible; MSIE 6.0; Symbian OS; 701) Opera 8.65 [de],symbian,DetectSymbianOS(),Low,A poorly selling (but great) UIQ phone. One of Sony Ericsson's last UIQ devices.,International,http://www.mobile-phone-specs.com/model/sonyericsson_w960i_ver1/
mobile,Samsung,TBD,Tizen,Tizen,"Mozilla/5.0 (SAMSUNG; SAMSUNG-GT-i9500/1.0; U; Tizen/1.0 like Android; en-us) AppleWebKit/534.46 (KHTML, like Gecko) SLP Browser/1.0 Mobile","tizen, mobile, webkit","DetectTizen(),
DetectWebKit(),
DetectTierIphone(), DetectSmartphone()",Low,Tizen is a new Linux-based smartphone platform being launched by Samsung and Intel. Browser capabilities are expected to be at least as good as Android's. ,International,"From a MobileESP community member, December 2012"
TV,Samsung,Various,Tizen TV,Browser,"Mozilla/5.0 (SMART-TV; Linux; Tizen 2.3) AppleWebkit/538.1 (KHTML, like Gecko) SamsungBrowser/1.0 TV Safari/538.1","tizen, smart-tv",DetectTizenTV(),Low,Samsung is committed to Tizen for its smart TV platform. ,International,http://developer.samsung.com/technical-doc/view.do?v=T000000203
mobile,Various,Various,Ubuntu Mobile,Browser,Mozilla/5.0 (Linux; Ubuntu 14.04 like Android 4.4) AppleWebKit/537.36 Chromium/35.0.1870.2 Mobile Safari/537.36,"ubuntu, mobile","DetectUbuntu(), DetectUbuntuPhone(), DetectTierIphone(), DetectSmartphone(), DetectMobileQuick(), DetectWebkit()",Low,Potential new up and coming mobile OS.,International,https://plus.google.com/+SimosXenitellis/posts/hfnnDpgFEZA
tablet,Various,Various,Ubuntu Mobile,Browser,None available yet,"ubuntu, tablet","DetectUbuntu(), DetectUbuntuTablet(), DetectTierTablet()",Low,Potential new up and coming mobile OS. This Tablet method is speculative right now pending confirmation of useragent. ,International,http://daker.me/2013/11/ubuntu-touch-user-agent.html
tablet,HP,TouchPad,WebOS,WebOS,"Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.2; U; en-US) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/234.40.1 Safari/534.6 TouchPad/1.0",hpwos,DetectWebOSTablet(),High,HP WebOS-based TouchPad tablet,International,http://www.zytrax.com/tech/web/mobile_ids.html
mobile,Palm,Pre,WebOS,WebOS (WebKit-based),"Mozilla/5.0 (webOS/1.0; U; en-US) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/1.0 Safari/525.27.1 Pre/1.0",webos,DetectPalmWebOS(),Medium,The Palm Pre was the first WebOS device.,International,http://www.zytrax.com/tech/web/mobile_ids.html
TV,LG,Various,WebOS TV,Browser,"Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/538.2 (KHTML, like Gecko) Large Screen WebAppManager Safari/538.2","webos, smarttv",DetectWebOSTV(),Low,LG is committed to WebOS for its smart TV platform. ,International,http://developer.lge.com/webOSTV/develop/web-app/webos-tv-platform/web-engine
desktop,Acer,Iconia W500,Windows,Internet Explorer,Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; MAAR; .NET4.0C),n/a,FALSE,High,"A tablet PC device probably launched with Windows 7. As with all ""desktop"" devices, should not be detected by MobileESP.",International,http://www.zytrax.com/tech/web/mobile_ids.html
game,Microsoft ,Xbox,Windows,Internet Explorer,Mozilla/5.0 (Windows NT 5.1; rv:6.0.2) xbox Gecko/20100101 Firefox/6.0.2,xbox,"DetectXbox(), DetectGameConsole()",Medium,A popular gaming console.,International,http://www.botsvsbrowsers.com/details/731405/index.html
mobile,Various,Various,Windows CE,Minimo,Mozilla/5.0 (Windows; U; Windows CE 5.1; rv:1.8.1a3) Gecko/20060610 Minimo/0.016,windows ce,"Unsupported
(Reports true for DetectWindowsMobile())",Low - LMP-B,This was basically an experimental version of Firefox that was only minimally released for WinCE PDAs. Predates Fennec.,International,http://www.zytrax.com/tech/web/mobile_ids.html
mobile,Various,Various,Windows CE,Opera Mobile,Opera/9.80 (Windows Mobile; WCE; Opera Mobi/WMD-50433; U; en) Presto/2.4.13 Version/10.00,opera,DetectOperaMobile(),Medium,Opera Mobile 10.0 running on Windows Mobile.,International,http://www.zytrax.com/tech/web/browser_ids.htm
mobile,Various,Various,"Windows CE
(PocketPC ?)",MS IE Mobile,Mozilla/4.0 (compatible; MSIE 6.0; Windows CE; IEMobile 7.11),"windows ce, iemobile",DetectWindowsMobile(),Low - OD,Such as Palm-branded PocketPC devices and the HTC Touch.,International,http://www.zytrax.com/tech/web/browser_ids.htm
mobile,Dell,Venue Pro,Windows Phone,MS IE Mobile,Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; DELL; Venue Pro),windows phone os 7,DetectWindowsPhone7(),High,"Dell Venue Pro, a Windows Phone 7 device",International,http://www.zytrax.com/tech/web/mobile_ids.html
mobile,HTC,8x,Windows Phone,Internet Explorer,Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; HTC; 0002),windows phone 8,"DetectWindowsPhone8(), DetectTierIphone(), DetectSmartphone()",High,HTC's flagship WP8 device for late 2012 and going into 2013.,USA & International,http://developer.att.com/developer/device_detailSpec.jsp?id=12600013
mobile,Nokia,Lumia 900,Windows Phone,Internet Explorer,Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; NOKIA; Lumia 900),windows phone os 7,"DetectWindowsPhone7(), DetectTierIphone(), DetectSmartphone()",High,Nokia's flagship WP7 device for 2012.,USA & International,http://www.developer.nokia.com/Community/Wiki/User-Agent_headers_for_Nokia_devices
mobile,Nokia,Lumia 920,Windows Phone,Internet Explorer,Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920),windows phone 8,"DetectWindowsPhone8(), DetectTierIphone(), DetectSmartphone()",High,Nokia's flagship WP8 device for late 2012 and going into 2013.,USA & International,http://www.developer.nokia.com/Community/Wiki/User-Agent_headers_for_Nokia_devices
mobile,Nokia,Lumia 800,Windows Phone ,Internet Explorer,"Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; NOKIA; Lumia 800)
",windows phone os 7,"DetectWindowsPhone7(), DetectTierIphone(), DetectSmartphone()",Medium,"One of Nokia's first, best Windows Phone devices (2011).",International,http://www.developer.nokia.com/Community/Wiki/User-Agent_headers_for_Nokia_devices
mobile,Palm,Treo 800w,Windows PocketPC,Internet Explorer,"Treo800w/v0100 Mozilla/4.0 (compatible; MSIE 4.01; Windows CE, PPC; 320x320) (compatible; MSIE 6.0; Windows CE; IEMobile 7.11)",windows ce,DetectWindowsMobile(),Low,One of Palm's more successful Windows Mobile devices. Released in 2008.,International,http://www.tera-wurfl.com/explore/?action=wurfl_id&id=palm_treo800w_ver1
================================================
FILE: PHP/mdetect.php
================================================
uagent_info();
}
//**************************
//The object initializer. Initializes several default variables.
function uagent_info()
{
$this->useragent = isset($_SERVER['HTTP_USER_AGENT'])?strtolower($_SERVER['HTTP_USER_AGENT']):'';
$this->httpaccept = isset($_SERVER['HTTP_ACCEPT'])?strtolower($_SERVER['HTTP_ACCEPT']):'';
//Let's initialize some values to save cycles later.
$this->InitDeviceScan();
}
//**************************
// Initialize Key Stored Values.
function InitDeviceScan()
{
//Save these properties to speed processing
global $isWebkit, $isIphone, $isAndroid, $isAndroidPhone;
$this->isWebkit = $this->DetectWebkit();
$this->isIphone = $this->DetectIphone();
$this->isAndroid = $this->DetectAndroid();
$this->isAndroidPhone = $this->DetectAndroidPhone();
//These tiers are the most useful for web development
global $isMobilePhone, $isTierTablet, $isTierIphone;
$this->isMobilePhone = $this->DetectMobileQuick();
$this->isTierIphone = $this->DetectTierIphone();
$this->isTierTablet = $this->DetectTierTablet();
//Optional: Comment these out if you NEVER use them.
global $isTierRichCss, $isTierGenericMobile;
$this->isTierRichCss = $this->DetectTierRichCss();
$this->isTierGenericMobile = $this->DetectTierOtherPhones();
$this->initCompleted = $this->true;
}
//**************************
//Returns the contents of the User Agent value, in lower case.
function Get_Uagent()
{
return $this->useragent;
}
//**************************
//Returns the contents of the HTTP Accept value, in lower case.
function Get_HttpAccept()
{
return $this->httpaccept;
}
//*****************************
// Start device detection
//*****************************
//**************************
// Detects if the current device is an iPhone.
function DetectIphone()
{
if ($this->initCompleted == $this->true ||
$this->isIphone == $this->true)
return $this->isIphone;
if (stripos($this->useragent, $this->deviceIphone) > -1)
{
//The iPad and iPod Touch say they're an iPhone. So let's disambiguate.
if ($this->DetectIpad() == $this->true ||
$this->DetectIpod() == $this->true)
return $this->false;
//Yay! It's an iPhone!
else
return $this->true;
}
else
return $this->false;
}
//**************************
// Detects if the current device is an iPod Touch.
function DetectIpod()
{
if (stripos($this->useragent, $this->deviceIpod) > -1)
return $this->true;
else
return $this->false;
}
//**************************
// Detects if the current device is an iPad tablet.
function DetectIpad()
{
if (stripos($this->useragent, $this->deviceIpad) > -1 &&
$this->DetectWebkit() == $this->true)
return $this->true;
else
return $this->false;
}
//**************************
// Detects if the current device is an iPhone or iPod Touch.
function DetectIphoneOrIpod()
{
//We repeat the searches here because some iPods may report themselves as an iPhone, which would be okay.
if ($this->DetectIphone() == $this->true ||
$this->DetectIpod() == $this->true)
return $this->true;
else
return $this->false;
}
//**************************
// Detects *any* iOS device: iPhone, iPod Touch, iPad.
function DetectIos()
{
if (($this->DetectIphoneOrIpod() == $this->true) ||
($this->DetectIpad() == $this->true))
return $this->true;
else
return $this->false;
}
//**************************
// Detects *any* Android OS-based device: phone, tablet, and multi-media player.
// Also detects Google TV.
function DetectAndroid()
{
if ($this->initCompleted == $this->true ||
$this->isAndroid == $this->true)
return $this->isAndroid;
if ((stripos($this->useragent, $this->deviceAndroid) > -1)
|| ($this->DetectGoogleTV() == $this->true))
return $this->true;
return $this->false;
}
//**************************
// Detects if the current device is a (small-ish) Android OS-based device
// used for calling and/or multi-media (like a Samsung Galaxy Player).
// Google says these devices will have 'Android' AND 'mobile' in user agent.
// Ignores tablets (Honeycomb and later).
function DetectAndroidPhone()
{
if ($this->initCompleted == $this->true ||
$this->isAndroidPhone == $this->true)
return $this->isAndroidPhone;
//First, let's make sure we're on an Android device.
if ($this->DetectAndroid() == $this->false)
return $this->false;
//If it's Android and has 'mobile' in it, Google says it's a phone.
if (stripos($this->useragent, $this->mobile) > -1)
return $this->true;
//Special check for Android devices with Opera Mobile/Mini. They should report here.
if (($this->DetectOperaMobile() == $this->true))
return $this->true;
return $this->false;
}
//**************************
// Detects if the current device is a (self-reported) Android tablet.
// Google says these devices will have 'Android' and NOT 'mobile' in their user agent.
function DetectAndroidTablet()
{
//First, let's make sure we're on an Android device.
if ($this->DetectAndroid() == $this->false)
return $this->false;
//Special check for Android devices with Opera Mobile/Mini. They should NOT report here.
if ($this->DetectOperaMobile() == $this->true)
return $this->false;
//Otherwise, if it's Android and does NOT have 'mobile' in it, Google says it's a tablet.
if (stripos($this->useragent, $this->mobile) > -1)
return $this->false;
else
return $this->true;
}
//**************************
// Detects if the current device is an Android OS-based device and
// the browser is based on WebKit.
function DetectAndroidWebKit()
{
if (($this->DetectAndroid() == $this->true) &&
($this->DetectWebkit() == $this->true))
return $this->true;
else
return $this->false;
}
//**************************
// Detects if the current device is a GoogleTV.
function DetectGoogleTV()
{
if (stripos($this->useragent, $this->deviceGoogleTV) > -1)
return $this->true;
else
return $this->false;
}
//**************************
// Detects if the current browser is based on WebKit.
function DetectWebkit()
{
if ($this->initCompleted == $this->true ||
$this->isWebkit == $this->true)
return $this->isWebkit;
if (stripos($this->useragent, $this->engineWebKit) > -1)
return $this->true;
else
return $this->false;
}
//**************************
// Detects if the current browser is a
// Windows Phone 7, 8, or 10 device.
function DetectWindowsPhone()
{
if (($this->DetectWindowsPhone7() == $this->true)
|| ($this->DetectWindowsPhone8() == $this->true)
|| ($this->DetectWindowsPhone10() == $this->true))
return $this->true;
else
return $this->false;
}
//**************************
// Detects a Windows Phone 7 device (in mobile browsing mode).
function DetectWindowsPhone7()
{
if (stripos($this->useragent, $this->deviceWinPhone7) > -1)
return $this->true;
else
return $this->false;
}
//**************************
// Detects a Windows Phone 8 device (in mobile browsing mode).
function DetectWindowsPhone8()
{
if (stripos($this->useragent, $this->deviceWinPhone8) > -1)
return $this->true;
else
return $this->false;
}
//**************************
// Detects a Windows Phone 10 device (in mobile browsing mode).
function DetectWindowsPhone10()
{
if (stripos($this->useragent, $this->deviceWinPhone10) > -1)
return $this->true;
else
return $this->false;
}
//**************************
// Detects if the current browser is a Windows Mobile device.
// Excludes Windows Phone 7 and later devices.
// Focuses on Windows Mobile 6.xx and earlier.
function DetectWindowsMobile()
{
if ($this->DetectWindowsPhone() == $this->true)
return $this->false;
//Most devices use 'Windows CE', but some report 'iemobile'
// and some older ones report as 'PIE' for Pocket IE.
if (stripos($this->useragent, $this->deviceWinMob) > -1 ||
stripos($this->useragent, $this->deviceIeMob) > -1 ||
stripos($this->useragent, $this->enginePie) > -1)
return $this->true;
//Test for Windows Mobile PPC but not old Macintosh PowerPC.
if (stripos($this->useragent, $this->devicePpc) > -1
&& !(stripos($this->useragent, $this->deviceMacPpc) > 1))
return $this->true;
//Test for certain Windwos Mobile-based HTC devices.
if (stripos($this->useragent, $this->manuHtc) > -1 &&
stripos($this->useragent, $this->deviceWindows) > -1)
return $this->true;
if ($this->DetectWapWml() == $this->true &&
stripos($this->useragent, $this->deviceWindows) > -1)
return $this->true;
else
return $this->false;
}
//**************************
// Detects if the current browser is any BlackBerry device.
// Includes BB10 OS, but excludes the PlayBook.
function DetectBlackBerry()
{
if ((stripos($this->useragent, $this->deviceBB) > -1) ||
(stripos($this->httpaccept, $this->vndRIM) > -1))
return $this->true;
if ($this->DetectBlackBerry10Phone() == $this->true)
return $this->true;
else
return $this->false;
}
//**************************
// Detects if the current browser is a BlackBerry 10 OS phone.
// Excludes tablets.
function DetectBlackBerry10Phone()
{
if ((stripos($this->useragent, $this->deviceBB10) > -1) &&
(stripos($this->useragent, $this->mobile) > -1))
return $this->true;
else
return $this->false;
}
//**************************
// Detects if the current browser is on a BlackBerry tablet device.
// Examples: PlayBook
function DetectBlackBerryTablet()
{
if ((stripos($this->useragent, $this->deviceBBPlaybook) > -1))
return $this->true;
else
return $this->false;
}
//**************************
// Detects if the current browser is a BlackBerry phone device AND uses a
// WebKit-based browser. These are signatures for the new BlackBerry OS 6.
// Examples: Torch. Includes the Playbook.
function DetectBlackBerryWebKit()
{
if (($this->DetectBlackBerry() == $this->true) &&
($this->DetectWebkit() == $this->true))
return $this->true;
else
return $this->false;
}
//**************************
// Detects if the current browser is a BlackBerry Touch phone device with
// a large screen, such as the Storm, Torch, and Bold Touch. Excludes the Playbook.
function DetectBlackBerryTouch()
{
if ((stripos($this->useragent, $this->deviceBBStorm) > -1) ||
(stripos($this->useragent, $this->deviceBBTorch) > -1) ||
(stripos($this->useragent, $this->deviceBBBoldTouch) > -1) ||
(stripos($this->useragent, $this->deviceBBCurveTouch) > -1))
return $this->true;
else
return $this->false;
}
//**************************
// Detects if the current browser is a BlackBerry OS 5 device AND
// has a more capable recent browser. Excludes the Playbook.
// Examples, Storm, Bold, Tour, Curve2
// Excludes the new BlackBerry OS 6 and 7 browser!!
function DetectBlackBerryHigh()
{
//Disambiguate for BlackBerry OS 6 or 7 (WebKit) browser
if ($this->DetectBlackBerryWebKit() == $this->true)
return $this->false;
if ($this->DetectBlackBerry() == $this->true)
{
if (($this->DetectBlackBerryTouch() == $this->true) ||
stripos($this->useragent, $this->deviceBBBold) > -1 ||
stripos($this->useragent, $this->deviceBBTour) > -1 ||
stripos($this->useragent, $this->deviceBBCurve) > -1)
{
return $this->true;
}
else
return $this->false;
}
else
return $this->false;
}
//**************************
// Detects if the current browser is a BlackBerry device AND
// has an older, less capable browser.
// Examples: Pearl, 8800, Curve1.
function DetectBlackBerryLow()
{
if ($this->DetectBlackBerry() == $this->true)
{
//Assume that if it's not in the High tier, then it's Low.
if (($this->DetectBlackBerryHigh() == $this->true) ||
($this->DetectBlackBerryWebKit() == $this->true))
return $this->false;
else
return $this->true;
}
else
return $this->false;
}
//**************************
// Detects if the current browser is the Nokia S60 Open Source Browser.
function DetectS60OssBrowser()
{
//First, test for WebKit, then make sure it's either Symbian or S60.
if ($this->DetectWebkit() == $this->true)
{
if (stripos($this->useragent, $this->deviceSymbian) > -1 ||
stripos($this->useragent, $this->deviceS60) > -1)
{
return $this->true;
}
else
return $this->false;
}
else
return $this->false;
}
//**************************
// Detects if the current device is any Symbian OS-based device,
// including older S60, Series 70, Series 80, Series 90, and UIQ,
// or other browsers running on these devices.
function DetectSymbianOS()
{
if (stripos($this->useragent, $this->deviceSymbian) > -1 ||
stripos($this->useragent, $this->deviceS60) > -1 ||
stripos($this->useragent, $this->deviceS70) > -1 ||
stripos($this->useragent, $this->deviceS80) > -1 ||
stripos($this->useragent, $this->deviceS90) > -1)
return $this->true;
else
return $this->false;
}
//**************************
// Detects if the current browser is on a PalmOS device.
function DetectPalmOS()
{
//Most devices nowadays report as 'Palm', but some older ones reported as Blazer or Xiino.
if (stripos($this->useragent, $this->devicePalm) > -1 ||
stripos($this->useragent, $this->engineBlazer) > -1 ||
stripos($this->useragent, $this->engineXiino) > -1)
{
//Make sure it's not WebOS first
if ($this->DetectPalmWebOS() == $this->true)
return $this->false;
else
return $this->true;
}
else
return $this->false;
}
//**************************
// Detects if the current browser is on a Palm device
// running the new WebOS.
function DetectPalmWebOS()
{
if (stripos($this->useragent, $this->deviceWebOS) > -1)
return $this->true;
else
return $this->false;
}
//**************************
// Detects if the current browser is on an HP tablet running WebOS.
function DetectWebOSTablet()
{
if ((stripos($this->useragent, $this->deviceWebOShp) > -1)
&& (stripos($this->useragent, $this->deviceTablet) > -1))
return $this->true;
else
return $this->false;
}
//**************************
// Detects if the current browser is on a WebOS smart TV.
function DetectWebOSTV()
{
if ((stripos($this->useragent, $this->deviceWebOStv) > -1)
&& (stripos($this->useragent, $this->smartTV2) > -1))
return $this->true;
else
return $this->false;
}
//**************************
// Detects if the current browser is Opera Mobile or Mini.
function DetectOperaMobile()
{
if ((stripos($this->useragent, $this->engineOpera) > -1) &&
((stripos($this->useragent, $this->mini) > -1) ||
(stripos($this->useragent, $this->mobi) > -1)))
return $this->true;
return $this->false;
}
//**************************
// Detects if the current device is an Amazon Kindle (eInk devices only).
// Note: For the Kindle Fire, use the normal Android methods.
function DetectKindle()
{
if (stripos($this->useragent, $this->deviceKindle) > -1 &&
$this->DetectAndroid() == $this->false)
return $this->true;
else
return $this->false;
}
//**************************
// Detects if the current Amazon device has turned on the Silk accelerated browsing feature.
// Note: Typically used by the the Kindle Fire.
function DetectAmazonSilk()
{
if (stripos($this->useragent, $this->engineSilk) > -1)
return $this->true;
else
return $this->false;
}
//**************************
// Detects if a Garmin Nuvifone device.
function DetectGarminNuvifone()
{
if (stripos($this->useragent, $this->deviceNuvifone) > -1)
return $this->true;
else
return $this->false;
}
//**************************
// Detects a device running the Bada OS from Samsung.
function DetectBada()
{
if (stripos($this->useragent, $this->deviceBada) > -1)
return $this->true;
else
return $this->false;
}
//**************************
// Detects a device running the Tizen smartphone OS.
function DetectTizen()
{
if ((stripos($this->useragent, $this->deviceTizen) > -1)
&& (stripos($this->useragent, $this->mobile) > -1))
return $this->true;
else
return $this->false;
}
//**************************
// Detects if the current browser is on a Tizen smart TV.
function DetectTizenTV()
{
if ((stripos($this->useragent, $this->deviceTizen) > -1)
&& (stripos($this->useragent, $this->smartTV1) > -1))
return $this->true;
else
return $this->false;
}
//**************************
// Detects a device running the Meego OS.
function DetectMeego()
{
if (stripos($this->useragent, $this->deviceMeego) > -1)
return $this->true;
else
return $this->false;
}
//**************************
// Detects a phone running the Meego OS.
function DetectMeegoPhone()
{
if ((stripos($this->useragent, $this->deviceMeego) > -1)
&& (stripos($this->useragent, $this->mobi) > -1))
return $this->true;
else
return $this->false;
}
//**************************
// Detects a mobile device (probably) running the Firefox OS.
function DetectFirefoxOS()
{
if (($this->DetectFirefoxOSPhone() == $this->true)
|| ($this->DetectFirefoxOSTablet() == $this->true))
return $this->true;
else
return $this->false;
}
//**************************
// Detects a phone (probably) running the Firefox OS.
function DetectFirefoxOSPhone()
{
//First, let's make sure we're NOT on another major mobile OS.
if ($this->DetectIos() == $this->true
|| $this->DetectAndroid() == $this->true
|| $this->DetectSailfish() == $this->true)
return $this->false;
if ((stripos($this->useragent, $this->engineFirefox) > -1) &&
(stripos($this->useragent, $this->mobile) > -1))
return $this->true;
return $this->false;
}
//**************************
// Detects a tablet (probably) running the Firefox OS.
function DetectFirefoxOSTablet()
{
//First, let's make sure we're NOT on another major mobile OS.
if ($this->DetectIos() == $this->true
|| $this->DetectAndroid() == $this->true
|| $this->DetectSailfish() == $this->true)
return $this->false;
if ((stripos($this->useragent, $this->engineFirefox) > -1) &&
(stripos($this->useragent, $this->deviceTablet) > -1))
return $this->true;
return $this->false;
}
//**************************
// Detects a device running the Sailfish OS.
function DetectSailfish()
{
if (stripos($this->useragent, $this->deviceSailfish) > -1)
return $this->true;
else
return $this->false;
}
//**************************
// Detects a phone running the Sailfish OS.
function DetectSailfishPhone()
{
if (($this->DetectSailfish() == $this->true) &&
(stripos($this->useragent, $this->mobile) > -1))
return $this->true;
return $this->false;
}
//**************************
// Detects a mobile device running the Ubuntu Mobile OS.
function DetectUbuntu()
{
if (($this->DetectUbuntuPhone() == $this->true)
|| ($this->DetectUbuntuTablet() == $this->true))
return $this->true;
else
return $this->false;
}
//**************************
// Detects a phone running the Ubuntu Mobile OS.
function DetectUbuntuPhone()
{
if ((stripos($this->useragent, $this->deviceUbuntu) > -1) &&
(stripos($this->useragent, $this->mobile) > -1))
return $this->true;
return $this->false;
}
//**************************
// Detects a tablet running the Ubuntu Mobile OS.
function DetectUbuntuTablet()
{
if ((stripos($this->useragent, $this->deviceUbuntu) > -1) &&
(stripos($this->useragent, $this->deviceTablet) > -1))
return $this->true;
return $this->false;
}
//**************************
// Detects the Danger Hiptop device.
function DetectDangerHiptop()
{
if (stripos($this->useragent, $this->deviceDanger) > -1 ||
stripos($this->useragent, $this->deviceHiptop) > -1)
return $this->true;
else
return $this->false;
}
//**************************
// Detects if the current browser is a Sony Mylo device.
function DetectSonyMylo()
{
if ((stripos($this->useragent, $this->manuSony) > -1) &&
((stripos($this->useragent, $this->qtembedded) > -1) ||
(stripos($this->useragent, $this->mylocom2) > -1)))
return $this->true;
else
return $this->false;
}
//**************************
// Detects if the current device is on one of the Maemo-based Nokia Internet Tablets.
function DetectMaemoTablet()
{
if (stripos($this->useragent, $this->maemo) > -1)
return $this->true;
//For Nokia N810, must be Linux + Tablet, or else it could be something else.
if ((stripos($this->useragent, $this->linux) > -1)
&& (stripos($this->useragent, $this->deviceTablet) > -1)
&& ($this->DetectWebOSTablet() == $this->false)
&& ($this->DetectAndroid() == $this->false))
return $this->true;
else
return $this->false;
}
//**************************
// Detects if the current device is an Archos media player/Internet tablet.
function DetectArchos()
{
if (stripos($this->useragent, $this->deviceArchos) > -1)
return $this->true;
else
return $this->false;
}
//**************************
// Detects if the current device is an Internet-capable game console.
// Includes many handheld consoles.
function DetectGameConsole()
{
if ($this->DetectSonyPlaystation() == $this->true)
return $this->true;
else if ($this->DetectNintendo() == $this->true)
return $this->true;
else if ($this->DetectXbox() == $this->true)
return $this->true;
else
return $this->false;
}
//**************************
// Detects if the current device is a Sony Playstation.
function DetectSonyPlaystation()
{
if (stripos($this->useragent, $this->devicePlaystation) > -1)
return $this->true;
else
return $this->false;
}
//**************************
// Detects if the current device is a handheld gaming device with
// a touchscreen and modern iPhone-class browser. Includes the Playstation Vita.
function DetectGamingHandheld()
{
if ((stripos($this->useragent, $this->devicePlaystation) > -1) &&
(stripos($this->useragent, $this->devicePlaystationVita) > -1))
return $this->true;
else
return $this->false;
}
//**************************
// Detects if the current device is a Nintendo game device.
function DetectNintendo()
{
if (stripos($this->useragent, $this->deviceNintendo) > -1 ||
stripos($this->useragent, $this->deviceWii) > -1 ||
stripos($this->useragent, $this->deviceNintendoDs) > -1)
return $this->true;
else
return $this->false;
}
//**************************
// Detects if the current device is a Microsoft Xbox.
function DetectXbox()
{
if (stripos($this->useragent, $this->deviceXbox) > -1)
return $this->true;
else
return $this->false;
}
//**************************
// Detects whether the device is a Brew-powered device.
function DetectBrewDevice()
{
if (stripos($this->useragent, $this->deviceBrew) > -1)
return $this->true;
else
return $this->false;
}
//**************************
// Detects whether the device supports WAP or WML.
function DetectWapWml()
{
if (stripos($this->httpaccept, $this->vndwap) > -1 ||
stripos($this->httpaccept, $this->wml) > -1)
return $this->true;
else
return $this->false;
}
//**************************
// Detects if the current device supports MIDP, a mobile Java technology.
function DetectMidpCapable()
{
if (stripos($this->useragent, $this->deviceMidp) > -1 ||
stripos($this->httpaccept, $this->deviceMidp) > -1)
return $this->true;
else
return $this->false;
}
//*****************************
// Device Classes
//*****************************
//**************************
// Check to see whether the device is *any* 'smartphone'.
// Note: It's better to use DetectTierIphone() for modern touchscreen devices.
function DetectSmartphone()
{
//Exclude duplicates from TierIphone
if (($this->DetectTierIphone() == $this->true)
|| ($this->DetectS60OssBrowser() == $this->true)
|| ($this->DetectSymbianOS() == $this->true)
|| ($this->DetectWindowsMobile() == $this->true)
|| ($this->DetectBlackBerry() == $this->true)
|| ($this->DetectMeegoPhone() == $this->true)
|| ($this->DetectPalmWebOS() == $this->true))
return $this->true;
else
return $this->false;
}
//**************************
// The quick way to detect for a mobile device.
// Will probably detect most recent/current mid-tier Feature Phones
// as well as smartphone-class devices. Excludes Apple iPads and other modern tablets.
function DetectMobileQuick()
{
if ($this->initCompleted == $this->true ||
$this->isMobilePhone == $this->true)
return $this->isMobilePhone;
//Let's exclude tablets
if ($this->isTierTablet == $this->true)
return $this->false;
//Most mobile browsing is done on smartphones
if ($this->DetectSmartphone() == $this->true)
return $this->true;
//Catch-all for many mobile devices
if (stripos($this->useragent, $this->mobile) > -1)
return $this->true;
if ($this->DetectOperaMobile() == $this->true)
return $this->true;
//We also look for Kindle devices
if ($this->DetectKindle() == $this->true ||
$this->DetectAmazonSilk() == $this->true)
return $this->true;
if (($this->DetectWapWml() == $this->true)
|| ($this->DetectMidpCapable() == $this->true)
|| ($this->DetectBrewDevice() == $this->true))
return $this->true;
if ((stripos($this->useragent, $this->engineNetfront) > -1)
|| (stripos($this->useragent, $this->engineUpBrowser) > -1))
return $this->true;
return $this->false;
}
//**************************
// The longer and more thorough way to detect for a mobile device.
// Will probably detect most feature phones,
// smartphone-class devices, Internet Tablets,
// Internet-enabled game consoles, etc.
// This ought to catch a lot of the more obscure and older devices, also --
// but no promises on thoroughness!
function DetectMobileLong()
{
if ($this->DetectMobileQuick() == $this->true)
return $this->true;
if ($this->DetectGameConsole() == $this->true)
return $this->true;
if (($this->DetectDangerHiptop() == $this->true)
|| ($this->DetectMaemoTablet() == $this->true)
|| ($this->DetectSonyMylo() == $this->true)
|| ($this->DetectArchos() == $this->true))
return $this->true;
if ((stripos($this->useragent, $this->devicePda) > -1) &&
!(stripos($this->useragent, $this->disUpdate) > -1))
return $this->true;
//Detect older phones from certain manufacturers and operators.
if ((stripos($this->useragent, $this->uplink) > -1)
|| (stripos($this->useragent, $this->engineOpenWeb) > -1)
|| (stripos($this->useragent, $this->manuSamsung1) > -1)
|| (stripos($this->useragent, $this->manuSonyEricsson) > -1)
|| (stripos($this->useragent, $this->manuericsson) > -1)
|| (stripos($this->useragent, $this->svcDocomo) > -1)
|| (stripos($this->useragent, $this->svcKddi) > -1)
|| (stripos($this->useragent, $this->svcVodafone) > -1))
return $this->true;
return $this->false;
}
//*****************************
// For Mobile Web Site Design
//*****************************
//**************************
// The quick way to detect for a tier of devices.
// This method detects for the new generation of
// HTML 5 capable, larger screen tablets.
// Includes iPad, Android (e.g., Xoom), BB Playbook, WebOS, etc.
function DetectTierTablet()
{
if ($this->initCompleted == $this->true ||
$this->isTierTablet == $this->true)
return $this->isTierTablet;
if (($this->DetectIpad() == $this->true)
|| ($this->DetectAndroidTablet() == $this->true)
|| ($this->DetectBlackBerryTablet() == $this->true)
|| ($this->DetectFirefoxOSTablet() == $this->true)
|| ($this->DetectUbuntuTablet() == $this->true)
|| ($this->DetectWebOSTablet() == $this->true))
return $this->true;
else
return $this->false;
}
//**************************
// The quick way to detect for a tier of devices.
// This method detects for devices which can
// display iPhone-optimized web content.
// Includes iPhone, iPod Touch, Android, Windows Phone, BB10, Playstation Vita, etc.
function DetectTierIphone()
{
if ($this->initCompleted == $this->true ||
$this->isTierIphone == $this->true)
return $this->isTierIphone;
if (($this->DetectIphoneOrIpod() == $this->true)
|| ($this->DetectAndroidPhone() == $this->true)
|| ($this->DetectWindowsPhone() == $this->true)
|| ($this->DetectBlackBerry10Phone() == $this->true)
|| ($this->DetectPalmWebOS() == $this->true)
|| ($this->DetectBada() == $this->true)
|| ($this->DetectTizen() == $this->true)
|| ($this->DetectFirefoxOSPhone() == $this->true)
|| ($this->DetectSailfishPhone() == $this->true)
|| ($this->DetectUbuntuPhone() == $this->true)
|| ($this->DetectGamingHandheld() == $this->true))
return $this->true;
//Note: BB10 phone is in the previous paragraph
if (($this->DetectBlackBerryWebKit() == $this->true) &&
($this->DetectBlackBerryTouch() == $this->true))
return $this->true;
else
return $this->false;
}
//**************************
// The quick way to detect for a tier of devices.
// This method detects for devices which are likely to be capable
// of viewing CSS content optimized for the iPhone,
// but may not necessarily support JavaScript.
// Excludes all iPhone Tier devices.
function DetectTierRichCss()
{
if ($this->initCompleted == $this->true ||
$this->isTierRichCss == $this->true)
return $this->isTierRichCss;
if ($this->DetectMobileQuick() == $this->true)
{
//Exclude iPhone Tier and e-Ink Kindle devices
if (($this->DetectTierIphone() == $this->true) ||
($this->DetectKindle() == $this->true))
return $this->false;
//The following devices are explicitly ok.
if ($this->DetectWebkit() == $this->true) //Any WebKit
return $this->true;
if ($this->DetectS60OssBrowser() == $this->true)
return $this->true;
//Note: 'High' BlackBerry devices ONLY
if ($this->DetectBlackBerryHigh() == $this->true)
return $this->true;
//Older Windows 'Mobile' isn't good enough for iPhone Tier.
if ($this->DetectWindowsMobile() == $this->true)
return $this->true;
if (stripos($this->useragent, $this->engineTelecaQ) > -1)
return $this->true;
//default
else
return $this->false;
}
else
return $this->false;
}
//**************************
// The quick way to detect for a tier of devices.
// This method detects for all other types of phones,
// but excludes the iPhone and RichCSS Tier devices.
function DetectTierOtherPhones()
{
if ($this->initCompleted == $this->true ||
$this->isTierGenericMobile == $this->true)
return $this->isTierGenericMobile;
//Exclude devices in the other 2 categories
if (($this->DetectMobileLong() == $this->true)
&& ($this->DetectTierIphone() == $this->false)
&& ($this->DetectTierRichCss() == $this->false))
return $this->true;
else
return $this->false;
}
}
//Was informed by a MobileESP user that it's a best practice
// to omit the closing ?> marks here. They can sometimes
// cause errors with HTML headers.
================================================
FILE: Python/mdetect.py
================================================
# *******************************************
# Copyright 2010-2016, Anthony Hand
#
#
# File version 2016.01.07 (May 13, 2015)
# Updates:
# - Fixed an issue in the detectNintendo() method. It was detecting for 'Nintendo' 3 times. Restored checks for Wii and Nintendo DS.
#
# File version 2015.05.13 (May 13, 2015)
# Updates:
# - Moved MobileESP to GitHub. https:#github.com/ahand/mobileesp
# - Opera Mobile/Mini browser has the same UA string on multiple platforms and doesn't differentiate phone vs. tablet.
# - Removed DetectOperaAndroidPhone(). This method is no longer reliable.
# - Removed DetectOperaAndroidTablet(). This method is no longer reliable.
# - Added support for Windows Phone 10: variable and DetectWindowsPhone10()
# - Updated DetectWindowsPhone() to include WP10.
# - Added support for Firefox OS.
# - A variable plus DetectFirefoxOS(), DetectFirefoxOSPhone(), DetectFirefoxOSTablet()
# - NOTE: Firefox doesn't add UA tokens to definitively identify Firefox OS vs. their browsers on other mobile platforms.
# - Added support for Sailfish OS. Not enough info to add a tablet detection method at this time.
# - A variable plus DetectSailfish(), DetectSailfishPhone()
# - Added support for Ubuntu Mobile OS.
# - DetectUbuntu(), DetectUbuntuPhone(), DetectUbuntuTablet()
# - Added support for 2 smart TV OSes. They lack browsers but do have WebViews for use by HTML apps.
# - One variable for Samsung Tizen TVs, plus DetectTizenTV()
# - One variable for LG WebOS TVs, plus DetectWebOSTV()
# - Added DetectTizen(). Tests for "mobile" to disambiguate from Samsung Smart TVs.
# - Removed variables for obsolete devices: deviceHtcFlyer, deviceXoom.
# - Updated DetectAndroid(). No longer has a special test case for the HTC Flyer tablet.
# - Updated DetectAndroidPhone().
# - Updated internal detection code for Android.
# - No longer has a special test case for the HTC Flyer tablet.
# - Checks against DetectOperaMobile() on Android and reports here if relevant.
# - Updated DetectAndroidTablet().
# - No longer has a special test case for the HTC Flyer tablet.
# - Checks against DetectOperaMobile() on Android to exclude it from here.
# - DetectMeego(): Changed definition for this method. Now detects any Meego OS device, not just phones.
# - DetectMeegoPhone(): NEW. For Meego phones. Ought to detect Opera browsers on Meego, as well.
# - DetectTierIphone(): Added support for phones running Sailfish, Ubuntu and Firefox Mobile.
# - DetectTierTablet(): Added support for tablets running Ubuntu and Firefox Mobile.
# - DetectSmartphone(): Added support for Meego phones.
# - Caught this library up to the PHP, JavaScript and Java versions. Updates include:
# - Added support for Bada: a variable and DetectBada(). This detects any Bada OS device, but (almost) all are phones.
# - Refactored the Windows Phone delegate-related properties and features. Now fires for any Windows Phone, not just WP7.
# - The event fires now when DetectWindowsPhone() is true.
# - Added support for Windows Phone 8: DetectWindowsPhone8().
# - Updated DetectWindowsMobile(). Excludes any Windows Phone device, not just WP7.
# - Added support for BlackBerry 10 OS phones: DetectBlackBerry10Phone().
# - Updated DetectSmartphone() to sync with the other libraries.
# - Updated DetectTierIphone() to sync with the other libraries.
# - OnInit(EventArgs e): Fixed the user agent and httpaccept init logic.
# - Refactored the detection logic in DetectMobileQuick() and DetectMobileLong().
# - Moved a few detection tests for older browsers to Long.
#
#
#
# File version date: Feburary 10, 2012
# Creation:
# - Cloned from http://code.google.com/p/mobileesp/source/browse/Java/UAgentInfo.java
# and http://code.google.com/p/mobileesp/source/browse/PHP/mdetect.php
# - Port to Python: Alexey Evseev (alexevseev@gmail.com)
# - Made for www.irk.fm website
#
#
#
# LICENSE INFORMATION
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
#
#
# ABOUT THIS PROJECT
# Project Owner: Anthony Hand
# Email: anthony.hand@gmail.com
# Web Site: http://www.mobileesp.com
# Source Files: https://github.com/ahand/mobileesp
#
# Versions of this code are available for:
# PHP, JavaScript, Java, ASP.NET (C#), Ruby and Python
#
# *******************************************
class UAgentInfo(object):
"""The UAgentInfo class encapsulates information about
a browser's connection to your web site.
You can use it to find out whether the browser asking for
your site's content is probably running on a mobile device.
The methods were written so you can be as granular as you want.
For example, enquiring whether it's as specific as an iPod Touch or
as general as a smartphone class device.
The object's methods return true, or false.
"""
# Initialize some initial smartphone string variables.
engineWebKit = "webkit"
deviceIphone = "iphone"
deviceIpod = "ipod"
deviceIpad = "ipad"
deviceMacPpc = "macintosh" #Used for disambiguation
deviceAndroid = "android"
deviceGoogleTV = "googletv"
deviceSymbian = "symbian"
deviceS60 = "series60"
deviceS70 = "series70"
deviceS80 = "series80"
deviceS90 = "series90"
deviceWinPhone7 = "windows phone os 7"
deviceWinPhone8 = "windows phone 8"
deviceWinPhone10 = "windows phone 10"
deviceWinMob = "windows ce"
deviceWindows = "windows"
deviceIeMob = "iemobile"
devicePpc = "ppc" #Stands for PocketPC
enginePie = "wm5 pie" #An old Windows Mobile
deviceBB = "blackberry"
deviceBB10 = "bb10" #For the new BB 10 OS
vndRIM = "vnd.rim" #Detectable when BB devices emulate IE or Firefox
deviceBBStorm = "blackberry95" #Storm 1 and 2
deviceBBBold = "blackberry97" #Bold 97x0 (non-touch)
deviceBBBoldTouch = "blackberry 99" #Bold 99x0 (touchscreen)
deviceBBTour = "blackberry96" #Tour
deviceBBCurve = "blackberry89" #Curve 2
deviceBBCurveTouch = "blackberry 938" #Curve Touch 9380
deviceBBTorch = "blackberry 98" #Torch
deviceBBPlaybook = "playbook" #PlayBook tablet
devicePalm = "palm"
deviceWebOS = "webos" #For Palm devices
deviceWebOStv = "web0s" #For LG TVs
deviceWebOShp = "hpwos" #For HP's line of WebOS devices
engineBlazer = "blazer" #Old Palm
engineXiino = "xiino" #Another old Palm
deviceKindle = "kindle" #Amazon Kindle, eInk one
engineSilk = "silk" #Amazon's accelerated Silk browser for Kindle Fire
deviceNuvifone = "nuvifone" #Garmin Nuvifone
deviceBada = "bada" #Samsung's Bada OS
deviceTizen = "tizen" #Tizen OS
deviceMeego = "meego" #Meego OS
deviceSailfish = "sailfish" #Sailfish OS
deviceUbuntu = "ubuntu" #Ubuntu Mobile OS
#Initialize variables for mobile-specific content.
vndwap = "vnd.wap"
wml = "wml"
#Initialize variables for other random devices and mobile browsers.
deviceTablet = "tablet" #Generic term for slate and tablet devices
deviceBrew = "brew"
deviceDanger = "danger"
deviceHiptop = "hiptop"
devicePlaystation = "playstation"
devicePlaystationVita = "vita"
deviceNintendoDs = "nitro"
deviceNintendo = "nintendo"
deviceWii = "wii"
deviceXbox = "xbox"
deviceArchos = "archos"
engineFirefox = "firefox" #For Firefox OS
engineOpera = "opera" #Popular browser
engineNetfront = "netfront" #Common embedded OS browser
engineUpBrowser = "up.browser" #common on some phones
engineOpenWeb = "openweb" #Transcoding by OpenWave server
deviceMidp = "midp" #a mobile Java technology
uplink = "up.link"
engineTelecaQ = "teleca q" #a modern feature phone browser
devicePda = "pda" #some devices report themselves as PDAs
mini = "mini" #Some mobile browsers put "mini" in their names.
mobile = "mobile" #Some mobile browsers put "mobile" in their user agent strings.
mobi = "mobi" #Some mobile browsers put "mobi" in their user agent strings.
#Smart TV strings
smartTV1 = "smart-tv" #Samsung Tizen smart TVs
smartTV2 = "smarttv" #LG WebOS smart TVs
#Use Maemo, Tablet, and Linux to test for Nokia"s Internet Tablets.
maemo = "maemo"
linux = "linux"
qtembedded = "qt embedded" #for Sony Mylo
mylocom2 = "com2" #for Sony Mylo also
#In some UserAgents, the only clue is the manufacturer.
manuSonyEricsson = "sonyericsson"
manuericsson = "ericsson"
manuSamsung1 = "sec-sgh"
manuSony = "sony"
manuHtc = "htc" #Popular Android and WinMo manufacturer
#In some UserAgents, the only clue is the operator.
svcDocomo = "docomo"
svcKddi = "kddi"
svcVodafone = "vodafone"
#Disambiguation strings.
disUpdate = "update" #pda vs. update
def __init__(self, userAgent, httpAccept):
"""Initialize the __userAgent and __httpAccept variables
Keyword arguments:
userAgent -- the User-Agent header
httpAccept -- the Accept header
"""
# User-Agent and Accept HTTP request headers
self.__userAgent = userAgent.lower() if userAgent else ""
self.__httpAccept = httpAccept.lower() if httpAccept else ""
# Let's store values for quickly accessing the same info multiple times.
self.__isIphone = False
self.__isAndroidPhone = False
self.__isTierTablet = False
self.__isTierIphone = False
self.__isTierRichCss = False
self.__isTierGenericMobile = False
# Intialize key stored values.
self.initDeviceScan()
def getUserAgent(self):
"""Return the lower case HTTP_USER_AGENT"""
return self.__userAgent
def getHttpAccept(self):
"""Return the lower case HTTP_ACCEPT"""
return self.__httpAccept
def getIsIphone(self):
"""Return whether the device is an Iphone or iPod Touch"""
return self.__isIphone
def getIsTierTablet(self):
"""Return whether the device is in the Tablet Tier."""
return self.__isTierTablet
def getIsTierIphone(self):
"""Return whether the device is in the Iphone Tier."""
return self.__isTierIphone
def getIsTierRichCss(self):
"""Return whether the device is in the 'Rich CSS' tier of mobile devices."""
return self.__isTierRichCss
def getIsTierGenericMobile(self):
"""Return whether the device is a generic, less-capable mobile device."""
return self.__isTierGenericMobile
def initDeviceScan(self):
"""Initialize Key Stored Values."""
self.__isIphone = self.detectIphoneOrIpod()
self.__isAndroidPhone = self.detectAndroidPhone()
self.__isTierTablet = self.detectTierTablet()
self.__isTierIphone = self.detectTierIphone()
self.__isTierRichCss = self.detectTierRichCss()
self.__isTierGenericMobile = self.detectTierOtherPhones()
def detectIphone(self):
"""Return detection of an iPhone
Detects if the current device is an iPhone.
"""
# The iPad and iPod touch say they're an iPhone! So let's disambiguate.
return UAgentInfo.deviceIphone in self.__userAgent \
and not self.detectIpad() \
and not self.detectIpod()
def detectIpod(self):
"""Return detection of an iPod Touch
Detects if the current device is an iPod Touch.
"""
return UAgentInfo.deviceIpod in self.__userAgent
def detectIpad(self):
"""Return detection of an iPad
Detects if the current device is an iPad tablet.
"""
return UAgentInfo.deviceIpad in self.__userAgent \
and self.detectWebkit()
def detectIphoneOrIpod(self):
"""Return detection of an iPhone or iPod Touch
Detects if the current device is an iPhone or iPod Touch.
"""
#We repeat the searches here because some iPods may report themselves as an iPhone, which would be okay.
return UAgentInfo.deviceIphone in self.__userAgent \
or UAgentInfo.deviceIpod in self.__userAgent
def detectIos(self):
"""Return detection of an Apple iOS device
Detects *any* iOS device: iPhone, iPod Touch, iPad.
"""
return self.detectIphoneOrIpod() \
or self.detectIpad()
def detectAndroid(self):
"""Return detection of an Android device
Detects *any* Android OS-based device: phone, tablet, and multi-media player.
Also detects Google TV.
"""
if UAgentInfo.deviceAndroid in self.__userAgent \
or self.detectGoogleTV():
return True
return False
def detectAndroidPhone(self):
"""Return detection of an Android phone
Detects if the current device is a (small-ish) Android OS-based device
used for calling and/or multi-media (like a Samsung Galaxy Player).
Google says these devices will have 'Android' AND 'mobile' in user agent.
Ignores tablets (Honeycomb and later).
"""
#First, let's make sure we're on an Android device.
if not self.detectAndroid():
return False
#If it's Android and has 'mobile' in it, Google says it's a phone.
if UAgentInfo.mobile in self.__userAgent:
return True
#Special check for Android devices with Opera Mobile/Mini. They should report here.
if self.detectOperaMobile():
return True
return False
def detectAndroidTablet(self):
"""Return detection of an Android tablet
Detects if the current device is a (self-reported) Android tablet.
Google says these devices will have 'Android' and NOT 'mobile' in their user agent.
"""
#First, let's make sure we're on an Android device.
if not self.detectAndroid():
return False
#Special check for Android devices with Opera Mobile/Mini. They should NOT report here.
if self.detectOperaMobile():
return False
#Otherwise, if it's Android and does NOT have 'mobile' in it, Google says it's a tablet.
return UAgentInfo.mobile not in self.__userAgent
def detectAndroidWebKit(self):
"""Return detection of an Android WebKit browser
Detects if the current device is an Android OS-based device and
the browser is based on WebKit.
"""
return self.detectAndroid() \
and self.detectWebkit()
def detectGoogleTV(self):
"""Return detection of GoogleTV
Detects if the current device is a GoogleTV.
"""
return UAgentInfo.deviceGoogleTV in self.__userAgent
def detectWebkit(self):
"""Return detection of a WebKit browser
Detects if the current browser is based on WebKit.
"""
return UAgentInfo.engineWebKit in self.__userAgent
def detectS60OssBrowser(self):
"""Return detection of Symbian S60 Browser
Detects if the current browser is the Symbian S60 Open Source Browser.
"""
#First, test for WebKit, then make sure it's either Symbian or S60.
return self.detectWebkit() \
and (UAgentInfo.deviceSymbian in self.__userAgent \
or UAgentInfo.deviceS60 in self.__userAgent)
def detectSymbianOS(self):
"""Return detection of SymbianOS
Detects if the current device is any Symbian OS-based device,
including older S60, Series 70, Series 80, Series 90, and UIQ,
or other browsers running on these devices.
"""
return UAgentInfo.deviceSymbian in self.__userAgent \
or UAgentInfo.deviceS60 in self.__userAgent \
or UAgentInfo.deviceS70 in self.__userAgent \
or UAgentInfo.deviceS80 in self.__userAgent \
or UAgentInfo.deviceS90 in self.__userAgent
def detectWindowsPhone(self):
"""Return detection of a Windows Phone device
Detects if the current browser is a
Windows Phone 7, 8, or 10 device
"""
return self.detectWindowsPhone7() \
or self.detectWindowsPhone8() \
or self.detectWindowsPhone10()
def detectWindowsPhone7(self):
"""Return detection of Windows Phone 7
Detects if the current browser is a
Windows Phone 7 device.
"""
return UAgentInfo.deviceWinPhone7 in self.__userAgent
def detectWindowsPhone8(self):
"""Return detection of Windows Phone 8
Detects if the current browser is a
Windows Phone 8 device.
"""
return UAgentInfo.deviceWinPhone8 in self.__userAgent
def detectWindowsPhone10(self):
"""Return detection of Windows Phone 10
Detects if the current browser is a
Windows Phone 10 device.
"""
return UAgentInfo.deviceWinPhone10 in self.__userAgent
def detectWindowsMobile(self):
"""Return detection of Windows Mobile
Detects if the current browser is a Windows Mobile device.
Excludes Windows Phone 7 devices.
Focuses on Windows Mobile 6.xx and earlier.
"""
#Exclude new Windows Phone.
if self.detectWindowsPhone():
return False
#Most devices use 'Windows CE', but some report 'iemobile'
# and some older ones report as 'PIE' for Pocket IE.
# We also look for instances of HTC and Windows for many of their WinMo devices.
if UAgentInfo.deviceWinMob in self.__userAgent \
or UAgentInfo.deviceIeMob in self.__userAgent \
or UAgentInfo.enginePie in self.__userAgent:
return True
# Test for certain Windwos Mobile-based HTC devices.
if UAgentInfo.manuHtc in self.__userAgent \
and UAgentInfo.deviceWindows in self.__userAgent:
return True
if self.detectWapWml() \
and UAgentInfo.deviceWindows in self.__userAgent:
return True
#Test for Windows Mobile PPC but not old Macintosh PowerPC.
return UAgentInfo.devicePpc in self.__userAgent \
and UAgentInfo.deviceMacPpc not in self.__userAgent
def detectBlackBerry(self):
"""Return detection of Blackberry
Detects if the current browser is any BlackBerry.
Includes the PlayBook.
"""
return UAgentInfo.deviceBB in self.__userAgent \
or UAgentInfo.vndRIM in self.__httpAccept
def detectBlackBerry10Phone(self):
"""Return detection of a Blackberry 10 OS phone
Detects if the current browser is a BlackBerry 10 OS phone.
Excludes the PlayBook.
"""
return UAgentInfo.deviceBB10 in self.__userAgent \
and UAgentInfo.mobile in self.__userAgent
def detectBlackBerryTablet(self):
"""Return detection of a Blackberry Tablet
Detects if the current browser is on a BlackBerry tablet device.
Example: PlayBook
"""
return UAgentInfo.deviceBBPlaybook in self.__userAgent
def detectBlackBerryWebKit(self):
"""Return detection of a Blackberry device with WebKit browser
Detects if the current browser is a BlackBerry device AND uses a
WebKit-based browser. These are signatures for the new BlackBerry OS 6.
Examples: Torch. Includes the Playbook.
"""
return self.detectBlackBerry() \
and self.detectWebkit()
def detectBlackBerryTouch(self):
"""Return detection of a Blackberry touchscreen device
Detects if the current browser is a BlackBerry Touch
device, such as the Storm, Torch, and Bold Touch. Excludes the Playbook.
"""
return UAgentInfo.deviceBBStorm in self.__userAgent \
or UAgentInfo.deviceBBTorch in self.__userAgent \
or UAgentInfo.deviceBBBoldTouch in self.__userAgent \
or UAgentInfo.deviceBBCurveTouch in self.__userAgent
def detectBlackBerryHigh(self):
"""Return detection of a Blackberry device with a better browser
Detects if the current browser is a BlackBerry device AND
has a more capable recent browser. Excludes the Playbook.
Examples, Storm, Bold, Tour, Curve2
Excludes the new BlackBerry OS 6 and 7 browser!!
"""
#Disambiguate for BlackBerry OS 6 or 7 (WebKit) browser
if self.detectBlackBerryWebKit():
return False
if not self.detectBlackBerry():
return False
return self.detectBlackBerryTouch() \
or UAgentInfo.deviceBBBold in self.__userAgent \
or UAgentInfo.deviceBBTour in self.__userAgent \
or UAgentInfo.deviceBBCurve in self.__userAgent
def detectBlackBerryLow(self):
"""Return detection of a Blackberry device with a poorer browser
Detects if the current browser is a BlackBerry device AND
has an older, less capable browser.
Examples: Pearl, 8800, Curve1
"""
if not self.detectBlackBerry():
return False
#Assume that if it's not in the High tier, then it's Low
return self.detectBlackBerryHigh() \
or self.detectBlackBerryWebKit()
def detectPalmOS(self):
"""Return detection of a PalmOS device
Detects if the current browser is on a PalmOS device.
"""
#Most devices nowadays report as 'Palm', but some older ones reported as Blazer or Xiino.
if UAgentInfo.devicePalm in self.__userAgent \
or UAgentInfo.engineBlazer in self.__userAgent \
or UAgentInfo.engineXiino in self.__userAgent:
# Make sure it's not WebOS
return not self.detectPalmWebOS()
return False
def detectPalmWebOS(self):
"""Return detection of a Palm WebOS device
Detects if the current browser is on a Palm device
running the new WebOS.
"""
return UAgentInfo.deviceWebOS in self.__userAgent
def detectWebOSTablet(self):
"""Return detection of an HP WebOS tablet
Detects if the current browser is on an HP tablet running WebOS.
"""
return UAgentInfo.deviceWebOShp in self.__userAgent \
and UAgentInfo.deviceTablet in self.__userAgent
def detectWebOSTV(self):
"""Return detection of a WebOS smart TV
Detects if the current browser is on a WebOS smart TV.
"""
return UAgentInfo.deviceWebOStv in self.__userAgent \
and UAgentInfo.smartTV2 in self.__userAgent
def detectGarminNuvifone(self):
"""Return detection of a Garmin Nuvifone
Detects if the current browser is a
Garmin Nuvifone.
"""
return UAgentInfo.deviceNuvifone in self.__userAgent
def detectBada(self):
"""Return detection of a Bada device
Detects a device running the Bada OS from Samsung.
"""
return UAgentInfo.deviceBada in self.__userAgent
def detectTizen(self):
"""Return detection of a Tizen device
Detects a device running the Tizen smartphone OS.
"""
return UAgentInfo.deviceTizen in self.__userAgent \
and UAgentInfo.mobile in self.__userAgent
def detectTizenTV(self):
"""Return detection of a Tizen smart TV
Detects if the current browser is on a Tizen smart TV.
"""
return UAgentInfo.deviceTizen in self.__userAgent \
and UAgentInfo.smartTV1 in self.__userAgent
def detectMeego(self):
"""Return detection of a Meego device
Detects a device running the Meego OS.
"""
return UAgentInfo.deviceMeego in self.__userAgent
def detectMeegoPhone(self):
"""Return detection of a Meego phone
Detects a phone running the Meego OS.
"""
return UAgentInfo.deviceMeego in self.__userAgent \
and UAgentInfo.mobi in self.__userAgent
def detectFirefoxOS(self):
"""Return detection of a Firefox OS mobile device
Detects a mobile device (probably) running the Firefox OS.
"""
return self.detectFirefoxOSPhone() \
or self.detectFirefoxOSTablet()
def detectFirefoxOSPhone(self):
"""Return detection of a Firefox OS phone
Detects a phone (probably) running the Firefox OS.
"""
if self.detectIos() \
or self.detectAndroid() \
or self.detectSailfish():
return False
if UAgentInfo.engineFirefox in self.__userAgent \
and UAgentInfo.mobile in self.__userAgent:
return True
return False
def detectFirefoxOSTablet(self):
"""Return detection of a Firefox OS tablet
Detects a tablet (probably) running the Firefox OS.
"""
if self.detectIos() \
or self.detectAndroid() \
or self.detectSailfish():
return False
if UAgentInfo.engineFirefox in self.__userAgent \
and UAgentInfo.deviceTablet in self.__userAgent:
return True
return False
def detectSailfish(self):
"""Return detection of a Sailfish OS device.
Detects a device running the Sailfish OS.
"""
return UAgentInfo.deviceSailfish in self.__userAgent
def detectSailfishPhone(self):
"""Return detection of a Sailfish phone
Detects a phone running the Sailfish OS.
"""
if self.detectSailfish() \
and UAgentInfo.mobile in self.__userAgent:
return True
return False
def detectUbuntu(self):
"""Return detection of an Ubuntu Mobile OS mobile device
Detects a mobile device running the Ubuntu Mobile OS.
"""
return self.detectUbuntuPhone() \
or self.detectUbuntuTablet()
def detectUbuntuPhone(self):
"""Return detection of an Ubuntu Mobile OS phone
Detects a phone running the Ubuntu Mobile OS.
"""
if UAgentInfo.deviceUbuntu in self.__userAgent \
and UAgentInfo.mobile in self.__userAgent:
return True
return False
def detectUbuntuTablet(self):
"""Return detection of an Ubuntu Mobile OS tablet
Detects a tablet running the Ubuntu Mobile OS.
"""
if UAgentInfo.deviceUbuntu in self.__userAgent \
and UAgentInfo.deviceTablet in self.__userAgent:
return True
return False
def detectBrewDevice(self):
"""Return detection of a Brew device
Detects whether the device is a Brew-powered device.
"""
return UAgentInfo.deviceBrew in self.__userAgent
def detectDangerHiptop(self):
"""Return detection of a Danger Hiptop
Detects the Danger Hiptop device.
"""
return UAgentInfo.deviceDanger in self.__userAgent \
or UAgentInfo.deviceHiptop in self.__userAgent
def detectOperaMobile(self):
"""Return detection of an Opera browser for a mobile device
Detects Opera Mobile or Opera Mini.
"""
return UAgentInfo.engineOpera in self.__userAgent \
and (UAgentInfo.mini in self.__userAgent \
or UAgentInfo.mobi in self.__userAgent)
def detectWapWml(self):
"""Return detection of a WAP- or WML-capable device
Detects whether the device supports WAP or WML.
"""
return UAgentInfo.vndwap in self.__httpAccept \
or UAgentInfo.wml in self.__httpAccept
def detectKindle(self):
"""Return detection of a Kindle
Detects if the current device is an Amazon Kindle (eInk devices only).
Note: For the Kindle Fire, use the normal Android methods.
"""
return UAgentInfo.deviceKindle in self.__userAgent \
and not self.detectAndroid()
def detectAmazonSilk(self):
"""Return detection of an Amazon Kindle Fire in Silk mode.
Detects if the current Amazon device is using the Silk Browser.
Note: Typically used by the the Kindle Fire.
"""
return UAgentInfo.engineSilk in self.__userAgent
def detectSonyPlaystation(self):
"""Return detection of Sony Playstation
Detects if the current device is a Sony Playstation.
"""
return UAgentInfo.devicePlaystation in self.__userAgent
def detectGamingHandheld(self):
"""Return detection of a gaming handheld with a modern iPhone-class browser
Detects if the current device is a handheld gaming device with
a touchscreen and modern iPhone-class browser. Includes the Playstation Vita.
"""
return UAgentInfo.devicePlaystation in self.__userAgent \
and UAgentInfo.devicePlaystationVita in self.__userAgent
def detectNintendo(self):
"""Return detection of Nintendo
Detects if the current device is a Nintendo game device.
"""
return UAgentInfo.deviceNintendo in self.__userAgent \
or UAgentInfo.deviceWii in self.__userAgent \
or UAgentInfo.deviceNintendoDs in self.__userAgent
def detectXbox(self):
"""Return detection of Xbox
Detects if the current device is a Microsoft Xbox.
"""
return UAgentInfo.deviceXbox in self.__userAgent
def detectGameConsole(self):
"""Return detection of any Game Console
Detects if the current device is an Internet-capable game console.
"""
return self.detectSonyPlaystation() \
or self.detectNintendo() \
or self.detectXbox()
def detectMidpCapable(self):
"""Return detection of a MIDP mobile Java-capable device
Detects if the current device supports MIDP, a mobile Java technology.
"""
return UAgentInfo.deviceMidp in self.__userAgent \
or UAgentInfo.deviceMidp in self.__httpAccept
def detectMaemoTablet(self):
"""Return detection of a Maemo OS tablet
Detects if the current device is on one of the Maemo-based Nokia Internet Tablets.
"""
if UAgentInfo.maemo in self.__userAgent:
return True
return UAgentInfo.linux in self.__userAgent \
and UAgentInfo.deviceTablet in self.__userAgent \
and not self.detectWebOSTablet() \
and not self.detectAndroid()
def detectArchos(self):
"""Return detection of an Archos media player
Detects if the current device is an Archos media player/Internet tablet.
"""
return UAgentInfo.deviceArchos in self.__userAgent
def detectSonyMylo(self):
"""Return detection of a Sony Mylo device
Detects if the current browser is a Sony Mylo device.
"""
return UAgentInfo.manuSony in self.__userAgent \
and (UAgentInfo.qtembedded in self.__userAgent
or UAgentInfo.mylocom2 in self.__userAgent)
#*****************************
# Device Classes
#*****************************
def detectSmartphone(self):
"""Return detection of a general smartphone device
Checks to see whether the device is *any* 'smartphone'.
Note: It's better to use DetectTierIphone() for modern touchscreen devices.
"""
return self.detectTierIphone() \
or self.detectS60OssBrowser() \
or self.detectSymbianOS() \
or self.detectWindowsMobile() \
or self.detectBlackBerry() \
or self.detectMeegoPhone() \
or self.detectPalmWebOS()
def detectMobileQuick(self):
"""Return detection of any mobile device using the quicker method
Detects if the current device is a mobile device.
This method catches most of the popular modern devices.
Excludes Apple iPads and other modern tablets.
"""
#Let's exclude tablets
if self.__isTierTablet:
return False
#Most mobile browsing is done on smartphones
if self.detectSmartphone():
return True
#Catch-all for many mobile devices
if UAgentInfo.mobile in self.__userAgent:
return True
if self.detectOperaMobile():
return True
#We also look for Kindle devices
if self.detectKindle() \
or self.detectAmazonSilk():
return True
if self.detectWapWml() \
or self.detectMidpCapable() \
or self.detectBrewDevice():
return True
if UAgentInfo.engineNetfront in self.__userAgent \
or UAgentInfo.engineUpBrowser in self.__userAgent:
return True
return False
def detectMobileLong(self):
"""Return detection of any mobile device using the more thorough method
The longer and more thorough way to detect for a mobile device.
Will probably detect most feature phones,
smartphone-class devices, Internet Tablets,
Internet-enabled game consoles, etc.
This ought to catch a lot of the more obscure and older devices, also --
but no promises on thoroughness!
"""
if self.detectMobileQuick() \
or self.detectGameConsole():
return True
if self.detectDangerHiptop() \
or self.detectMaemoTablet() \
or self.detectSonyMylo() \
or self.detectArchos():
return True
if UAgentInfo.devicePda in self.__userAgent \
and UAgentInfo.disUpdate not in self.__userAgent:
return True
#detect older phones from certain manufacturers and operators.
return UAgentInfo.uplink in self.__userAgent \
or UAgentInfo.engineOpenWeb in self.__userAgent \
or UAgentInfo.manuSamsung1 in self.__userAgent \
or UAgentInfo.manuSonyEricsson in self.__userAgent \
or UAgentInfo.manuericsson in self.__userAgent \
or UAgentInfo.svcDocomo in self.__userAgent \
or UAgentInfo.svcKddi in self.__userAgent \
or UAgentInfo.svcVodafone in self.__userAgent
#*****************************
# For Mobile Web Site Design
#*****************************
def detectTierTablet(self):
"""Return detection of any device in the Tablet Tier
The quick way to detect for a tier of devices.
This method detects for the new generation of
HTML 5 capable, larger screen tablets.
Includes iPad, Android (e.g., Xoom), BB Playbook, WebOS, etc.
"""
return self.detectIpad() \
or self.detectAndroidTablet() \
or self.detectBlackBerryTablet() \
or self.detectFirefoxOSTablet() \
or self.detectUbuntuTablet() \
or self.detectWebOSTablet()
def detectTierIphone(self):
"""Return detection of any device in the iPhone/Android/WP7/WebOS Tier
The quick way to detect for a tier of devices.
This method detects for devices which can
display iPhone-optimized web content.
Includes iPhone, iPod Touch, Android, Windows Phone 7, Palm WebOS, etc.
"""
return self.__isIphone \
or self.__isAndroidPhone \
or self.detectWindowsPhone() \
or self.detectBlackBerry10Phone() \
or self.detectPalmWebOS() \
or self.detectBada() \
or self.detectTizen() \
or self.detectFirefoxOSPhone() \
or self.detectSailfishPhone() \
or self.detectUbuntuPhone() \
or self.detectGamingHandheld()
def detectTierRichCss(self):
"""Return detection of any device in the 'Rich CSS' Tier
The quick way to detect for a tier of devices.
This method detects for devices which are likely to be capable
of viewing CSS content optimized for the iPhone,
but may not necessarily support JavaScript.
Excludes all iPhone Tier devices.
"""
#The following devices are explicitly ok.
#Note: 'High' BlackBerry devices ONLY
if not self.detectMobileQuick():
return False
#Exclude iPhone Tier and e-Ink Kindle devices
if self.detectTierIphone() \
or self.detectKindle():
return False
#The following devices are explicitly ok.
#Note: 'High' BlackBerry devices ONLY
#Older Windows 'Mobile' isn't good enough for iPhone Tier.
return self.detectWebkit() \
or self.detectS60OssBrowser() \
or self.detectBlackBerryHigh() \
or self.detectWindowsMobile() \
or UAgentInfo.engineTelecaQ in self.__userAgent
def detectTierOtherPhones(self):
"""Return detection of a mobile device in the less capable tier
The quick way to detect for a tier of devices.
This method detects for all other types of phones,
but excludes the iPhone and RichCSS Tier devices.
"""
#Exclude devices in the other 2 categories
return self.detectMobileLong() \
and not self.detectTierIphone() \
and not self.detectTierRichCss()
================================================
FILE: README.md
================================================
# MobileESP
[](http://blog.mobileesp.com/?page_id=13)
[](http://blog.mobileesp.com/?page_id=53)
[](http://blog.mobileesp.com/?page_id=53)
[](http://blog.mobileesp.com/?page_id=53)
[](http://blog.mobileesp.com/?page_id=53)
[](http://blog.mobileesp.com/?page_id=53)
[](http://blog.mobileesp.com/?page_id=53)
At last, a dead simple way for web site publishers to detect visitors on mobile web sites!
MobileESP is free, open source and lightweight. MobileESP has a simple API for detecting mobile devices. The API returns the simple Boolean result of TRUE if the device is the specified type, or FALSE if it isn't. For example, want to know if your visitor is on an iPhone, Android or Windows Phone device? Simply use the method DetectTierIphone(). It's that easy.
Visit the MobileESP web site for tons more information: www.MobileESP.org.
## Core Principles
MobileESP believes in making it dead easy for a website publisher to detect mobile visitors. As a result, the API follows the DetectXXX() pattern and returns a simple Boolean (true or false) for the type of mobile device or platform desired. The API DetectXXX() methods are consistent by design across supported platforms.
In addition, a second core principle is that the code is easy for the user to read and understand. Therefore, we believe it's easier for the user to change, update or extend the library, if desired.
The code is also purposefully written to be modular so that it is not only easier to maintain, but also easier to extend.
## Server-Side Platforms
> API Documentation
MobileESP started with PHP (and JavaScript) and has been extended by the community to a bunch of other platforms:
- PHP
- Java
- ASP.NET (C#)
- Python
- C++
Also available in separate repositories:
- Ruby: This project was ported by Martin, who separately maintains the Ruby codebase on GitHub.
- Classic ASP (VBscript): This project was ported by Miguel Barrero, who separately maintains the codebase on BitBucket.
## Client-Side Platforms
> JavaScript API Documentation
MobileESP is also available for JavaScript to be run in the browser. Support for client-side JavaScript processing on phones is very poor to completely non-existent. Though much better on modern smartphones, JavaScript is still not quite at the desktop level. Generally speaking, JavaScript is probably reliable only for distinguishing between devices among modern smartphones and tablets. So if you want to know whether your visitor is one of these devices, the JavaScript probably works fine: iPhone, Android, Windows Phone, and BlackBerry 10+. A few other modern smartphone OSes such as Sailfish and Ubuntu are also expected to perform well.
A server-side library is recommended for pretty much everything else: from older smartphone OSes to all feature phones, plus smart TVs, gaming devices, and ereaders.
## Live Demo
Anthony updates the live demo pages when he updates the library. The live demo pages show the results of each of the API calls. Point your mobile device browser to the parent demo page: http://www.hand-interactive.com/detect/
- PHP Demo Page
- JavaScript Demo Page
## Useragent Test Strings
The MobileESP project tests the PHP and JavaScript live demos with the included spreadsheet of useragent strings. This set of useragent strings isn't meant to be exhaustive, but rather to feature a wide variety of strings to verify that each of the DetectXXX() methods work as expected. Feel free to use this list of useragent strings on your own project, as well.
## Updated May 2015!
Anthony provided a much-needed update in May 2015. Please see the change log in the beginning of each file for full details.
Anthony tested the PHP and JavaScript libraries with the new useragent strings in the spreadsheet. However, Anthony doesn't have the environments set up to test the Java, C#, Python and C++ libraries. Can you help to test these?
In addition, the Ruby and Classic ASP (VBScript) libraries haven't been updated in several years. Would anyone be interested in updating them?
## Python Question
We've been notified that the Python library doesn't follow the Python community coding standards regarding method names in lower case with underscores separating elements rather than camel case. What do y'all think about this? Would it be better to conform to the Python standards or keep the method names consistent between libraries? Please let Anthony know.
## Backstory
This project maintains and extends the original code created in 2008 by Anthony Hand of Hand Interactive (http://www.hand-interactive.com). Anthony was working on a web site project for a client and wanted an easy way to customize some of the content for smartphones, especially that era's flagship iPhone, Symbian, and BlackBerry devices. However, commonly used Grep-style algorithms at the time were dumb, blunt force tools treating all devices as equal. Thus the PHP and JavaScript libraries were originally born.
NOTE: The MobileESP project was previously hosted on the Google Code web site. Because Google closed down that site and there had been many user requests, MobileESP is now hosted with GitHub.
## YouTube Quick Talk Video
MobileESP founder, Anthony Hand, gave a short 6 minute talk on the origin and basics of MobileESP at a Silicon Valley event in 2012. Check it out!
https://youtu.be/F_mFNTbe9lQ
## License
Apache v2.0. More info and the link to the Apache v2.0 license page in each code file.
## Important Caveat
The MobileESP project code is lightweight and ideal for many web sites. However, this project is not meant to replace other projects offering greater specificity and control, such as WURFL or HandsetDetection.com.
## Donations
Yes, usage of the MobileESP code is FREE, so no worries about that. But a donation to the cause helps provide motivation for Anthony to frequently update the code and continue to enhance the cross-platform APIs. And get new phones to do new tests with!
> Donation Info
================================================
FILE: composer.json
================================================
{
"name": "ahand/mobileesp",
"type": "library",
"version": "3.0.0",
"description": "Since 2008, MobileESP provides web site developers an easy-to-use and lightweight API for detecting whether visitors are using a mobile device, and if so, what kind. The APIs provide simple boolean results ('true' or 'false') for identifying individual device categories (such as iPhone, BlackBerry, Android, and Windows Mobile), device capabilities (e.g., J2ME), and broad classes of devices, such as 'iPhone Tier' (iPhone/Android/Tizen) or 'Tablet Tier.' APIs are available in PHP, JavaScript, Java, C#, Ruby Python, and more.",
"keywords": ["mobile","mobile detect","mobile esp","mobile redirect","mobile view managing","mobile-detect","mobile detector","mobile device","detect iphone","detect ipad","detect tablet","detect android","mobiledetect","responsive web","useragent","browser","user agent"],
"authors": [
{
"name": "Anthony Hand",
"email": "anthony.hand@gmail.com",
"role": "Maintainer"
}
],
"homepage": "http://www.mobileesp.org",
"license": "Apache-2.0",
"support": {
"issues": "https://github.com/ahand/mobileesp/issues",
"source": "https://github.com/ahand/mobileesp/"
},
"autoload": {
"classmap": ["PHP"]
},
"minimum-stability": "stable"
}