Reputation: 465
i am developing a webapp and i want to separate UIs for desktops and mobile devices, so i want to check wether the client using my app is a mobile device or not.
I tried to look online for official documentation or vaadin forum , but i couldn't find any useful information, since almost all of the solutions proposed in those answers are not implementable any more (the methods were removed).
Upvotes: 2
Views: 1517
Reputation: 465
If anyone is interested i found a way around CSS, even if i think it's a bit limited.
I used HttpServletRequest
, VaadinService
and VaadinServletRequest
: I basically checked if words like "Mobile", "iPhone" or "Android" are in the request.
It's not an elegant solution, but it works. This is the code:
public static boolean isPhone(HttpServletRequest request) {
String url = request.getHeader("User-Agent");
return (url.contains("iPhone") || url.contains("Android"));
}
Upvotes: 0
Reputation: 1091
You can use VaadinSession.getCurrent().getBrowser()
to see if your client is a phone or not.
public boolean isMobileDevice() {
WebBrowser webBrowser = VaadinSession.getCurrent().getBrowser();
return webBrowser.isAndroid() || webBrowser.isIPhone() || webBrowser.isWindowsPhone();
}
Upvotes: 9