admin管理员组文章数量:1391836
Here is the code to recognize the tablet devices using the spring mobile dependency but it is not working and kept returning null, do you know any solution?
public static boolean isTablet(HttpServletRequest request) {
var res = ResolverUtils.isTablet(DeviceUtils.getCurrentDevice(request), getSitePreference(request));
return res;
}
private static SitePreference getSitePreference(HttpServletRequest request) {
String param = request.getParameter("site_preference");
if ("normal".equalsIgnoreCase(param)) {
return SitePreference.NORMAL;
} else if ("mobile".equalsIgnoreCase(param)) {
return SitePreference.MOBILE;
} else if ("tablet".equalsIgnoreCase(param)) {
return SitePreference.TABLET;
}
return null;
}
Also I tried com.github.ua-parser
but it is not recognizing the tablet devices too, here is my code for this one too :
private static final Parser UA_PARSER = new Parser();
public static boolean isTablet(HttpServletRequest request) {
String userAgent = request.getHeader("User-Agent");
if (userAgent == null) {
return false; // No User-Agent means we cannot detect the device
}
Client client = UA_PARSER.parse(userAgent);
Device device = client.device;
// Check if the device is a tablet (common pattern)
return device.family != null && device.family.toLowerCase().contains("tablet");
}
本文标签: htmlHow to recognise tablet devices in browsers in javaStack Overflow
版权声明:本文标题:html - How to recognise tablet devices in browsers in java - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744737991a2622444.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论