Recently, I have been upgrading my company's mobile phone site and made a dedicated touch screen version. After doing this, I tried to use the Agent to determine the corresponding smartphone device, after unremitting efforts, I finally collected the Agent of a relatively full range of smart devices and wrote a program. I hope it will help you.
Copy codeThe Code is as follows: // <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 and 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