0
点赞
收藏
分享

微信扫一扫

判断请求来自浏览器还是手机工具类

_鱼与渔_ 2022-10-09 阅读 102


/**
* 判断请求来自浏览器还是手机
*/
public class IsMobileUtil {
private final static String[] agent = { "Android", "iPhone", "iPod","iPad", "Windows Phone", "MQQBrowser" }; //定义移动端请求的所有可能类型

/**
* 判断User-Agent 是不是来自于手机
* @param ua
* @return
*/
public static boolean isMobileDevice(String ua) {
boolean flag = false;
if (!ua.contains("Windows NT") || (ua.contains("Windows NT") && ua.contains("compatible; MSIE 9.0;"))) {
// 排除 苹果桌面系统
if (!ua.contains("Windows NT") && !ua.contains("Macintosh")) {
for (String item : agent) {
if (ua.contains(item)) {
flag = true;
break;
}
}
}
}
return flag;
}
}

 

举报

相关推荐

0 条评论