Reputation: 13471
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?
Upvotes: 2
Views: 2391
Reputation: 3035
I know that this ticket is quite old, but I just wanted to inform you that it is possible with newer versions of spring-mobile-device.
In the latest 1.1.5.RELEASE you can easily access the Device's DevicePlatform. See https://github.com/spring-projects/spring-mobile/blob/1.1.5.RELEASE/spring-mobile-device/src/main/java/org/springframework/mobile/device/DevicePlatform.java
So if you use 1.1.5.RELEASE, you can easily do something like this:
if (currentDevice.isNormal()) {
// do stuff for desktop devices
} elseif (currentDevice.getDevicePlattform() == DevicePlatform.IOS) {
// do iOS specific stuff
} else {
// treat as mobile device
}
Upvotes: 1
Reputation: 2179
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.
Upvotes: 3