Search code examples
iosspringspring-mvcmobile-websitespring-mobile

Can Spring Mobile Treat iOS and Android Differently?


Spring Mobile allows a Spring MVC application to detect whether a web client is a desktop/laptop, tablet, or mobile device.

Is it possible to determine if a device is Android/iOS using Spring Mobile? Are there extension points for this, or would it be 'homebrew' functionality?


Solution

  • Spring Mobile does not include built in support to differentiate between Android and iOS. However, it includes two interfaces, Device and DeviceResolver. You can implement custom versions of these that detect Android and iOS devices and offer additional methods, such as isAndroid() or isIOS() for example. Then you can configure DeviceResolverHandlerInterceptor to use your DeviceResolver implementation. When you use the detected device in a Controller you can simply cast it to your implementation. Review the provided LiteDevice and LiteDeviceResolver implementations for inspiration.