UserAgentUtil
Origin
User Agent, abbreviated as UA, is a special string header that allows servers to identify the operating system and version, browser and version, and browser rendering engine used by clients.
Hutool supports the parsing of User-Agent after version 4.2.1.
Usage
Taking desktop browsers as an example, assuming you have obtained the user’s UA:
String uaStr = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1";
Obtaining UA information
We can use the UserAgentUtil.parse
method to parse the UA:
UserAgent ua = UserAgentUtil.parse(uaStr);
ua.getBrowser().toString(); // Chrome
ua.getVersion(); // 14.0.835.163
ua.getEngine().toString(); // Webkit
ua.getEngineVersion(); // 535.1
ua.getOs().toString(); // Windows 7
ua.getPlatform().toString(); // Windows
Determining if the device is a mobile terminal
ua.isMobile();