Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>UserAgent detection code continued:</p> <pre><code> /** * * 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 device. * @return detection of Windows Phone 7 */ public boolean detectWindowsPhone7() { if (userAgent.indexOf(deviceWinPhone7) != -1) { return true; } return false; } /** * Detects if the current browser is a Windows Mobile device. * Excludes Windows Phone 7 devices. * Focuses on Windows Mobile 6.xx and earlier. * @return detection of Windows Mobile */ public boolean detectWindowsMobile() { //Exclude new Windows Phone 7. if (detectWindowsPhone7()) { 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 &amp;&amp; userAgent.indexOf(deviceWindows) != -1) || (detectWapWml() &amp;&amp; userAgent.indexOf(deviceWindows) != -1)) { return true; } //Test for Windows Mobile PPC but not old Macintosh PowerPC. if (userAgent.indexOf(devicePpc) != -1 &amp;&amp; !(userAgent.indexOf(deviceMacPpc) != -1)) return true; return false; } /** * Detects if the current browser is any BlackBerry. * Includes the PlayBook. * @return detection of Blackberry */ public boolean detectBlackBerry() { if (userAgent.indexOf(deviceBB) != -1 || httpAccept.indexOf(vndRIM) != -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() &amp;&amp; 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() &amp;&amp; (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 &amp;&amp; userAgent.indexOf(deviceTablet) != -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; } /** * Check to see whether the device is any device * in the 'smartphone' category. * @return detection of a general smartphone device */ public boolean detectSmartphone() { return (isIphone || isAndroidPhone || isTierIphone || detectS60OssBrowser() || detectSymbianOS() || detectWindowsMobile() || detectWindowsPhone7() || detectBlackBerry() || detectPalmWebOS() || detectPalmOS() || detectGarminNuvifone()); } /** * 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 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 Opera Mobile or Opera Mini. * @return detection of an Opera browser for a mobile device */ public boolean detectOperaMobile() { if (userAgent.indexOf(engineOpera) != -1 &amp;&amp; (userAgent.indexOf(mini) != -1 || userAgent.indexOf(mobi) != -1)) { return true; } return false; } /** * Detects Opera Mobile on an Android phone. * @return detection of an Opera browser on an Android phone */ public boolean detectOperaAndroidPhone() { if (userAgent.indexOf(engineOpera) != -1 &amp;&amp; (userAgent.indexOf(deviceAndroid) != -1 &amp;&amp; userAgent.indexOf(mobi) != -1)) { return true; } return false; } /** * Detects Opera Mobile on an Android tablet. * @return detection of an Opera browser on an Android tablet */ public boolean detectOperaAndroidTablet() { if (userAgent.indexOf(engineOpera) != -1 &amp;&amp; (userAgent.indexOf(deviceAndroid) != -1 &amp;&amp; userAgent.indexOf(deviceTablet) != -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 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 &amp;&amp; !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 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; } if (detectWapWml() || detectBrewDevice() || detectOperaMobile()) { return true; } if ((userAgent.indexOf(engineNetfront) != -1) || (userAgent.indexOf(engineUpBrowser) != -1) || (userAgent.indexOf(engineOpenWeb) != -1)) { return true; } if (detectDangerHiptop() || detectMidpCapable() || detectMaemoTablet() || detectArchos()) { return true; } if ((userAgent.indexOf(devicePda) != -1) &amp;&amp; (userAgent.indexOf(disUpdate) &lt; 0)) //no index found { return true; } if (userAgent.indexOf(mobile) != -1) { return true; } //We also look for Kindle devices if (detectKindle() || detectAmazonSilk()) { 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 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 if the current device is an Internet-capable game console. * @return detection of any Game Console */ public boolean detectGameConsole() { if (detectSonyPlaystation() || detectNintendo() || detectXbox()) { 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; } /** * 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 &amp;&amp; userAgent.indexOf(deviceTablet) != -1 &amp;&amp; !detectWebOSTablet() &amp;&amp; !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 browser is a Sony Mylo device. * @return detection of a Sony Mylo device */ public boolean detectSonyMylo() { if (userAgent.indexOf(manuSony) != -1 &amp;&amp; (userAgent.indexOf(qtembedded) != -1 || userAgent.indexOf(mylocom2) != -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() || detectSonyMylo()) { return true; } //detect older phones from certain manufacturers and operators. if (userAgent.indexOf(uplink) != -1) { return true; } if (userAgent.indexOf(manuSonyEricsson) != -1) { return true; } if (userAgent.indexOf(manuericsson) != -1) { return true; } if (userAgent.indexOf(manuSamsung1) != -1) { return true; } if (userAgent.indexOf(svcDocomo) != -1) { return true; } if (userAgent.indexOf(svcKddi) != -1) { return true; } if (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() || 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, Palm WebOS, etc. * @return detection of any device in the iPhone/Android/WP7/WebOS Tier */ public boolean detectTierIphone() { if (isIphone || isAndroidPhone || (detectBlackBerryWebKit() &amp;&amp; detectBlackBerryTouch()) || detectWindowsPhone7() || detectPalmWebOS() || detectGarminNuvifone()) { 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() &amp;&amp; !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() &amp;&amp; !detectTierIphone() &amp;&amp; !detectTierRichCss()) { return true; } return false; } } </code></pre> <p>Much appreciated work by Anthony Hand</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload