Device Detection module

Multi-experience support Bundled: Community Edition

Edition CE

License

MLA, GPL

Issues

Maven site

Latest

1.1

The Device Detection module helps manage the complexity of mobile environments. The module detects requests originating from mobile devices using Mobile Detect, a lightweight Java library for detecting mobile devices. Coupled with Magnolia’s channels functionality, you can create channels that define the content and format served to a particular device class. There is no need to duplicate content. The same web content can be served to all devices in a format that is optimized for each device.

Installing with Maven

Bundled modules are automatically installed for you.

If the module is unbundled, add the following to your bundle including your project’s <dependencyManagement> section and your webapp’s <dependencies> section. If the module is unbundled but the version is managed by the parent POM, add the following to your webapp’s <dependencies> section.

<dependency>
  <groupId>info.magnolia.devdect</groupId>
  <artifactId>magnolia-module-device-detection</artifactId>
  <version>1.1</version> (1)
</dependency>
1 Should you need to specify the module version, do it using <version>.

Configuration

The default configuration detects mobile devices, splitting them into two groups: smartphones and tablets. You don’t need to change anything unless you want to detect other types of devices or other capabilities.

Device detection filter

info.magnolia.module.devicedetection.filter.DeviceDetectionFilter is registered in the Magnolia filter chain at Configuration > /server/filters/deviceDetection. The purpose of this filter is to intercept the incoming request and discover the capabilities of the device based on its User-Agent header.

Device detection filter configuration

All devices identify themselves in the User-Agent request header. Here is an example what the header looks like when an iPhone 3GS requests the Magnolia corporate home page. The header basically says ``I am an iPhone running iOS 4.0.2 and the Safari browser''.

GET / HTTP/1.1
Host: www.magnolia-cms.com
Connection: close
User-Agent: Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0_2 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A400 Safari/6531.22.7

Device capability configuration

The Mobile Detect API provides the capabilities of mobile devices. It knows the specifications of several devices, broken down into groups. The API is built into the Device Detection module so no calls to outside services are needed during detection. Mobile Detect is a clone of Mobile ESP. We use the clone rather than the original because the clone provides a Maven artifact so we do not need to include the API code.

The API is registered in the Configuration app in /modules/device-detection/config/capability.

API registered in the Configuration app

The device detection filter asks the API if the requesting device is a smartphone or a tablet device. Once the device capabilities are identified, the filter creates a info.magnolia.module.devicedetection.DeviceInfo object in the request and sets the following basic properties:

  • isSmartphone is true if the device is a smartphone.

  • isTablet is true if the device is a tablet.

If you want to implement your own device detection mechanism, look at these Java classes for examples.

Class Description

info.magnolia.module.devicedetection.DeviceDetectionModule

Implements ModuleLifecycle and ensures the costly initCapability method in DeviceCapability is called only once.

info.magnolia.module.devicedetection.mobiledetect.MobileDetectDeviceCapability

Implements the info.magnolia.module.devicedetection.DeviceCapability interface and provides information about the capabilities of the device. Gets DeviceInfo.

info.magnolia.module.devicedetection.DeviceInfo

Provides information about the device. All attributes are initially set to defined defaults.

Device channel configuration

In order to serve content to the device in an appropriate format, a channel is resolved next. info.magnolia.module.devicedetection.DeviceChannelResolver is registered in the Configuration app (/server/rendering/channelManagement/channels). This resolver resolves the channel to use based on the DeviceInfo object.

Device channel configuration

The channel is mapped to a variation. The variation consists of templates and a theme that optimizes the content for displaying on the device.

Feedback

DX Core

×

Location

This widget lets you know where you are on the docs site.

You are currently perusing through the DX Core docs.

Main doc sections

DX Core Headless PaaS Legacy Cloud Incubator modules