Use useragent to determine smart phones (devices, Android, and iOS)

Source: Internet
Author: User

Recently, I have been upgrading my company's mobile phone site and made a touch-screen version dedicated. after doing so, I tried to use the agent to determine the corresponding smartphone device and then jumped to the new mobile phone site.

After unremitting efforts, I finally collected the agent of comprehensive smart devices, and then wroteProgram, DirectlyCodeHope to help you

 

 ///  <Summary>  
/// Determine whether the agent is a smartphone
/// </Summary>
/// <Returns> </returns>
Public Static Bool Checkagent ()
{
Bool Flag = False ;

String Agent = httpcontext. Current. Request. useragent;
String [] KEYWORDS = { " Android " , " IPhone " , " IPod " , " IPad " , " Windows Phone " , " Mqqbrowser " };

// Exclude Windows Desktop
If (! Agent. Contains ( " Windows NT " ) | (Agent. Contains ( " Windows NT " ) & Agent. Contains ( " Compatible; MSIE: 9.0; " )))
{
// Exclude Apple Desktop
If (! Agent. Contains ( " Windows NT " )&&! Agent. Contains ( " Macintosh " ))
{
Foreach ( String Item In Keywords)
{
If (Agent. Contains (item ))
{
Flag = True ;
Break ;
}
}
}
}

Return Flag;
}

Code explanation:

1 .! Agent. Contains ("Windows NT ")&&! Agent. Contains ("Macintosh") exclude windows and Apple desktop systems

2. "android", "iPhone", "iPod", "iPad", "Windows Phone", and "mqqbrowser" are keywords used to judge the agent of a smart device.

3. The mqqbrowser is the QQ mobile phone browser. The agent of the QQ mobile phone is special, so it is determined separately.

 

The following are some of the agents that we have collected. It is difficult to find so many smart devices:

Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_2 like Mac OS X; ZH-CN) applewebkit/533.17.9 (khtml, like gecko) version/5.0.2 mobile/8h7 Safari/6533.18.5

Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; ZH-CN) applewebkit/533.17.9 (khtml, like gecko) version/5.0.2 mobile/8h7 Safari/6533.18.5

Mqqbrowser/25 (Linux; U; 2.3.3; ZH-CN; HTC Desire s build/gri40; 480*800)

Mozilla/5.0 (Linux; U; Android 2.3.3; ZH-CN; htc_desires_s510e build/gri40) applewebkit/533.1 (khtml, like gecko) version/4.0 mobile safari/533.1

Mozilla/5.0 (symbianos/9.3; U; series60/3.2 NokiaE75-1/110.48.125 profile/MIDP-2.1 configuration/CLDC-1.1) applewebkit/413 (khtml, like gecko) Safari/413

Mozilla/5.0 (IPAD; U; cpu OS 4_3_3 like Mac OS X; ZH-CN) applewebkit/533.17.9 (khtml, like gecko) mobile/8j2

Mozilla/5.0 (Windows NT 5.2) applewebkit/534.30 (khtml, like gecko) Chrome/12.0.742.122 Safari/534.30

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) applewebkit/535.1 (khtml, like gecko) Chrome/14.0.835.202 Safari/535.1

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) applewebkit/534.51.22 (khtml, like gecko) version/5.1.1 Safari/534.51.22

Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) applewebkit/534.46 (khtml, like gecko) version/5.1 mobile/9a5313e Safari/7534.48.3

Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) applewebkit/534.46 (khtml, like gecko) version/5.1 mobile/9a5313e Safari/7534.48.3

Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) applewebkit/534.46 (khtml, like gecko) version/5.1 mobile/9a5313e Safari/7534.48.3

Mozilla/5.0 (Windows NT 6.1) applewebkit/535.1 (khtml, like gecko) Chrome/14.0.835.202 Safari/535.1

Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; iemobile/9.0; Samsung; omnia7) ---- Samsung mp7

Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; xblwp7; zunewp7) ---- HTC mp7

Original article address: Judge smart devices (Android, IOS) through useragent)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.