Java uses user-agent to determine if it is a mobile browser

Source: Internet
Author: User

Constant-Constant class

 Public classConstant {//Browser Type     Public Static FinalString[] mobileagents = {"iphone", "Android", "Phone", "mobile", "WAP", "NetFront", "Java",            "Opera Mobi", "Opera Mini", "UCWeb", "Windows CE", "Symbian", "series", "webOS", "Sony", "BlackBerry",            "Dopod", "Nokia", "Samsung", "PalmSource", "XDA", "Pieplus", "Meizu", "MIDP", "CLDC", "Motorola", "Foma",            "DoCoMo", "Up.browser", "Up.link", "Blazer", "Helio", "Hosin", "Huawei", "Novarra", "Coolpad", "webOS",            "TechFaith", "PalmSource", "Alcatel", "Amoi", "Ktouch", "Nexian", "Ericsson", "Philips", "Sagem", "wellcom",            "Bunjalloo", "Maui", "Smartphone", "Iemobile", "Spice", "Bird", "zte-", "Longcos", "Pantech", "Gionee",            "Portalmmm", "Jig Browser", "Hiptop", "BenQ", "Haier", "^LCT", "320x320", "240x320", "176x220", "the",            "acs-", "Alav", "Alca", "Amoi", "Audi", "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", "oper", "palm", "pana", "Pant", "Phil", "Play", "Port", "ProX", "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", "wap-", "Wapa", "Wapi",            "Wapp", "WAPR", "Webc", "winw", "winw", "XDA", "xda-", "Googlebot-mobile" };}

Utils-Tool Class

    /*** * @Title: Judgelsmobile @Description: TODO (Judging if it is a mobile browser)@param @param* Request@param @returnsettings File@returnBoolean return type@throws     */     Public Static BooleanJudgelsmobile (HttpServletRequest request) {BooleanIsMobile =false; String[] Mobileagents=constant.mobileagents; if(Request.getheader ("user-agent")! =NULL) {             for(String mobileagent:mobileagents) {if(Request.getheader ("User-agent"). toLowerCase (). IndexOf (mobileagent) > 0) {IsMobile=true;  Break; }            }        }        returnIsMobile; }

Java uses user-agent to determine if it is a mobile browser

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.