How to identify the different user agent values for browsers in ADF Faces

Posted by

Place the below sample code in your application to receive the user agent values for diffent browsers like safari,
chrome ,IE , Mozilla

public String getUserAgentValue() {
FacesContext facesCtx = FacesContext.getCurrentInstance().getCurrentInstance();
ExternalContext externalctx = facesCtx.getExternalContext();
HttpServletRequest request = (HttpServletRequest)externalctx.getRequest();
String userAgentVal = null;
userAgentVal=request.getHeader(“User-Agent”);
userAgentVal=userAgentVal.toLowerCase();

if (userAgentVal != null && userAgentVal.indexOf(“iphone”) > -1) {
userAgentVal = “iPhone”;
}

else if (userAgentVal != null && userAgentVal.indexOf(“android”) > -1) {
if (userAgentVal.indexOf(“mobile”) > -1)
userAgentVal = “Android Phone”;
else
userAgentVal = “Android Tablet”;
}

else if (userAgentVal != null && userAgentVal.indexOf(“ipad”) > -1) {
userAgentVal = “iPad”;
}

else if (userAgentVal != null && userAgentVal.indexOf(“macintosh”) > -1) {
userAgentVal = “Macbook”;
}

else if (userAgentVal != null && userAgentVal.indexOf(“windows”) > -1) {
userAgentVal = “Windows”;
}

else
{
userAgentVal=”Could not identify…”;
}

return userAgentVal;
}