package com.hanchao.util;import java.util.regex.matcher;import java.util.regex.pattern;/** * @author liweihan () * @version 1.0 (November 28, 2014 2:31:56) * Check whether the mobile Access */public class CheckMobile { // \b is the word boundary (two consecutive Alphabetic characters and non-alphabetic characters) logical interval between, // strings are transcoded at compile time, So it is "\\b" // \B is the logical interval between the words inside the word (a two-letter character that is attached) static String phoneReg = "\\b (IP (hone|od) | Android|opera m (ob|in) i " + "|windows (phone|ce) |blackberry" + "|s (Ymbian|eries60|amsung) |p (LAYBOOK|ALM|ROFILE/MIDP" + "|laystation portable) |nokia|fennec|htc[-_]" + "|mobile|up.browser | [1-4] [0-9] {2}x[1-4][0-9]{2}) \\b "; static string tablereg = "\\b (ipad|tablet| ( nexus 7) |up.browser " + "| [1-4] [0-9] {2}x[1-4][0-9]{2}) \\b "; // Mobile device regular match: mobile, tablet static Pattern phonePat = Pattern.compile (phonereg, pattern.case_insensitive); Static pattern tablepat = pattern.compile (tablereg, pattern.case_insensitive); /** * detection is mobile device access * * @Title: check * @Date : 2014-7-7 Afternoon 01:29:07 * @param userAgent Browser ID * @return true: Mobile device access, FALSE:PC end Access */ public static boolean check (String useragent) { if (null == useragent) { useragent = ""; } // Matching Matcher matcherphone = phonepat.matcher (useragent); matcher matchertable = tablepat.matcher (userAgent); if (Matcherphone.find () | | matchertable.find ()) { return true; } else { return false; } } }
Reference article: http://www.cnblogs.com/rubylouvre/archive/2012/04/11/2442588.html
http://blog.csdn.net/xiaoxian8023/article/details/37527133
This article is from the "My Java World" blog, so be sure to keep this source http://hanchaohan.blog.51cto.com/2996417/1584251
java-to determine whether the mobile or PC-side access