说明:都是穷举,准确率不能够保证100%,尝试使用 分辨率+ua
1、C#
public static bool IsMobile() {
string m = "nokia|sony|ericsson|mot|samsung|sgh|lg|sie|philips|panasonic|alcatel|lenovo|cldc|midp|wap|mobile";
string ua = HttpContext.Current.Request.UserAgent;
if (Regex.IsMatch(ua, m, RegexOptions.IgnoreCase))
return true;
else
return false;
}
2、Java
static final String[] MOBILE_SPECIFIC_SUBSTRING = { "iPad","iPhone","Android","MIDP","Opera Mobi", "Opera Mini","BlackBerry","HP iPAQ","IEMobile", "MSIEMobile","Windows Phone","HTC","LG", "MOT","Nokia","Symbian","Fennec", "Maemo","Tear","Midori","armv", "Windows CE","WindowsCE","Smartphone","240x320", "176x220","320x320","160x160","webOS", "Palm","Sagem","Samsung","SGH", "SIE","SonyEricsson","MMP","UCWEB"};private boolean checkMobile() { String userAgent = request.getHeader("user-agent"); for (String mobile: MOBILE_SPECIFIC_SUBSTRING){ if (userAgent.contains(mobile) || userAgent.contains(mobile.toUpperCase()) || userAgent.contains(mobile.toLowerCase())){ return true; } } return false; }
3、
((System.Web.Configuration.HttpCapabilitiesBase)Request.Browser).IsMobileDevice