package com.cirle.scientific.utils;

import javax.servlet.http.HttpServletRequest;

public class DeviceUtil {

    public static boolean  isMobileDevice(HttpServletRequest request){
        String requestHeader = request.getHeader("user-agent");
        /**
         * android : 所有android设备
         * mac os : iphone ipad
         * windows phone:Nokia等windows系统的手机
         */
        String[] deviceArray = new String[]{"android","mac os","windows phone"};
        if(requestHeader == null){
            return false;
        }
        if(requestHeader.contains("Macintosh")){//针对苹果电脑。设置pc登录
            return false;
        }
        requestHeader = requestHeader.toLowerCase();
        for(int i=0;i<deviceArray.length;i++){
            if(requestHeader.indexOf(deviceArray[i])>0){
                return true;
            }
        }
        return false;
    }
}
