I am looking for a way to easily detect whether my user is on a tablet or on a fullblown pc. Any idea how to do that?
getSession().getBrowser().isTouchDevice() won't work with more and more pc's having a touchscreen. And getBrowser() is deprecated in Vaadin 7 anyhow.
I am not using vaadin-touchkit (should i?)
Regards, Rob.
Here is a one way for Vaadin 7:
in UI.init() you get the parameter VaadinRequest, which you can cast (after type check) to VaadinServletRequest and use the getHttpServletRequest to get the underlying HTTP request. This you can then use to check the "User-Agent". Something like:
if (request instanceof VaadinServletRequest) {
HttpServletRequest httpRequest = ((VaadinServletRequest)request).getHttpServletRequest();
String userAgent = httpRequest.getHeader("User-Agent").toLowerCase();
// TODO: Check user agent for all tablet matching keywords
if (userAgent.contains("ipad")) {
//...
}
}
You can also get the User-Agent HTTP header with
Page.getCurrent().getWebBrowser().getBrowserApplication()
It seems like there is no attribute sent in the headers to differenciate between tablet or pc but you can find out whether it's a touch screen by using.
if(Page.getCurrent().getWebBrowser().isTouchDevice()){ //..}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With