Frage

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?

War es hilfreich?

Lösung

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.

Andere Tipps

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
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top