User-agent Get phone type

Source: Internet
Author: User
Online search methods can not accurately show the model, the iphone can not be removed after the improvement, the code is as follows, but also need to further verify the changes:
Package org.mice.utils;
Import Java.util.regex.Matcher;

Import Java.util.regex.Pattern; /** * * Class Name: Miceutils.java * Class Description: Frequently Used class method * * @author CHENPH * @CreateDate: May 16, 2015 * @version 1.0/Public Class Miceutils {//Remove phone type from user-agent//static pattern = Pattern.compile ("; \\s? ( \\s*?\\s?\\s*?) \\s?  
	(build)?/"); Static pattern pattern = Pattern.compile ("; \\s?[ ^;\\s]*? (\\s?\\s*?) \\s?  
	
	(build)?/"); /** * Get phone type * @param agent * @return/public static string Getmobiletype (string agent) {if (Agent.indexof IP
		Hone ")!=-1) {return" IPhone ";  
	    } Matcher Matcher = Pattern.matcher (agent);  
	    String model = NULL;  
	        if (Matcher.find ()) {model = Matcher.group (1). Trim ();
	    return model;
	Return ""; public static void Main (String args[]) {//string agent = "mozilla/5.0" (Linux; U Android 5.0.2; ZH-CN; XT1079 build/lxb22.99-7.1) applewebkit/534.30 (khtml, like Gecko) version/4.0 ucbrowser/10.4.0.5580.8.0 Mobile safari/534.30 "; String Agent = "mozilla/5.0" (IPhone; CPU iPhone os 8_2 like Mac os X;
		ZH-CN) applewebkit/537.51.1 (khtml, like Gecko) mobile/12d508 ucbrowser/10.4.5.568 Mobile ";
	System.out.println (Miceutils.getmobiletype (agent));
 }
}


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.