cn.smallbun.scaffold.framework.common.toolkit.UserAgentUtil Maven / Gradle / Ivy
The newest version!
/*
* Copyright (c) 2018-2019.[zuoqinggang] www.pingfangushi.com
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package cn.smallbun.scaffold.framework.common.toolkit;
import eu.bitwalker.useragentutils.DeviceType;
import eu.bitwalker.useragentutils.UserAgent;
import javax.servlet.http.HttpServletRequest;
/**
* 用户代理实用程序工具类
*
* @author SanLi
* Created by [email protected] on 2018/9/2
*/
public class UserAgentUtil {
/**
* 获取用户代理对象
*
* @param request request
* @return UserAgent
*/
public static UserAgent getUserAgent(HttpServletRequest request) {
return UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
}
/**
* 获取设备类型
*
* @param request request
* @return DeviceType
*/
public static DeviceType getDeviceType(HttpServletRequest request) {
return getUserAgent(request).getOperatingSystem().getDeviceType();
}
/**
* 是否是PC
*
* @param request request
* @return boolean
*/
public static boolean isComputer(HttpServletRequest request) {
return DeviceType.COMPUTER.equals(getDeviceType(request));
}
/**
* 是否是手机
*
* @param request request
* @return boolean
*/
public static boolean isMobile(HttpServletRequest request) {
return DeviceType.MOBILE.equals(getDeviceType(request));
}
/**
* 是否是平板
*
* @param request request
* @return boolean
*/
public static boolean isTablet(HttpServletRequest request) {
return DeviceType.TABLET.equals(getDeviceType(request));
}
/**
* 是否是手机和平板
*
* @param request request
* @return boolean
*/
public static boolean isMobileOrTablet(HttpServletRequest request) {
DeviceType deviceType = getDeviceType(request);
return DeviceType.MOBILE.equals(deviceType) || DeviceType.TABLET.equals(deviceType);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy