Bir web sitesine istek yapan client'ın mobil cihaz mı değil mi olduğunu aşağıdaki fonksiyonu kullanarak anlayabilirsiniz :
public boolean isMobile(HttpServletRequest request) throws Exception { String user_agent = request.getHeader("user-agent"); String accept = request.getHeader("accept"); String x_wap_profile = request.getHeader("x-wap-profile"); String profile = request.getHeader("profile"); String opera = request.getHeader("X-OperaMini-Phone"); String ua_pixels = request.getHeader("ua-pixels"); if (user_agent != null) { if (user_agent.contains("windows") &&! user_agent.contains("windows ce")){ return false; } Pattern pattern = Pattern.compile("up.browser|up.link|windows ce|iphone| iemobile|mini|mmp|symbian|midp|wap|phone|pocket|mobile|pda|psp|android|nokia| blackberry|rim|opera mini|opera mobi|windows ce|windows phone|netfront|palm- |palm os|pre|palmsource|avantogo|webos|hiptop|iris|kddi|kindle|lg-|lge|mot-|motorola| nintendo ds|nitro|playstation portable|samsung|sanyo|sprint|sonyericsson| alcatel|audiovox|bird|coral|cricket|docomo|edl|huawei|htc|gt-|lava|ct|lg|lynx|mobile| lenovo|maui|micromax|mot|myphone|nec|nexian|nook|pantech|pg|polaris|ppc|sch |sec|spice|tianyu|ustarcom|utstarcom|" + "videocon|vodafone|winwap|zte", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(user_agent); if (matcher.find()){ return true; } String[] ua = {"acs-","alav","alca","amoi","audi","aste","avan", "benq","bird","blac","blaz", "brew","cell","cldc","cmd-","dang","doco","eric","hipt","inno", "ipaq","java","jigs", "kddi","keji","leno","lg-c","lg-d","lg-g","lge-","maui","maxo", "midp","mits","mmef", "mobi","mot-","moto","mwbp","nec-","newt","noki","opwv", "palm","pana","pant","pdxg", "phil","play","pluc","port","prox","qtek","qwap", "sage","sams","sany","sch-","sec-","send","seri","sgh-","shar","sie-","siem", "smal","smar","sony","sph-","symb","t-mo", "teli","tim-","tosh","tsm-","upg1","upsi", "vk-v","voda","w3c ","wap-","wapa","wapi", "wapp","wapr","webc", "winw","winw","xda","xda-"}; for(int i = 0; i < ua.length; i++ ) { if (ua[i] == user_agent.substring(0,3)) { return true; } } } if (accept != null) { if (accept.contains("text/vnd.wap.wml") || accept.contains("application/vnd.wap.xhtml+xml")) { return true; } } if (x_wap_profile != null || profile != null || opera != null || ua_pixels != null) { return true; } return false; }
Not : http://wiki.drupalschool.net/index.php/Use_Java_to_Detect_Mobile_Devices kaynağından yararlanılmıştır.