As you know, Internet traffic has risen exponentially over the past decade and shows no sign of stopping. With the latest and greatest devices, mobile Internet access has become the norm and is predicted to pass PC based Internet access soon. Because of the mobile boom, new obstacles and challenges are presented for content management. How will content adapt to all devices with different capabilities? How can your grandma’s gnarly tablet and cousin’s awesome new mobile phone request the same information from your portal?
The Device Detection API detects the capabilities of any device making a request to your portal. It can also determine what mobile device or operating system was used to make a request, and then follows rules to make Liferay render pages based on the device. To use this feature, you first need to install the Device Recognition Provider app from Liferay Marketplace. Find more information on the app by following one of these links, depending on whether you use Liferay CE or EE: Device Recognition CE or Device Recognition EE.
The Device Recognition plugin comes bundled inside the Device Recognition Provider app; it uses a device database called WURFL to determine the capabilities of your device. Visit the WURFL website for more information at http://wurfl.sourceforge.net/.
You can create your own plugin to use your device’s database. Let’s look at some simple uses of the Device Detection API and talk about its capabilities.
Using the Device API
Let’s look at a couple of code snippets to get you started. You can obtain the object
Device from the
themeDisplay object like this:
Device device = themeDisplay.getDevice();
You can view the API in the Device Javadocs. Using some of the methods from the Javadocs, here’s an example that obtains a device’s dimensions:
Dimensions dimensions = device.getScreenSize(); float height = dimensions.getHeight(); float width = dimensions.getWidth();
Now your code can get the
Device object and the dimensions of a device. Of course this is just a simple example; you can acquire many other device attributes that help you take care of the pesky problems that arise when sending content to different devices. You can refer to the Device Javadocs mentioned above for assistance. Let’s look at some device capabilities next.
Most of the capabilities of a device can be detected, depending on the device detection implementation you’re using. The Device Recognition plugin’s device database (WURFL) has a list of capabilities here. For example, you can obtain the capability of a brand name with this code:
String brand = device.getCapability("brand_name");
You can grab many other device capabilities, including
release_date. You can also get boolean values like
With the Device Detection API, you can detect the capabilities of a device making request to your portal and render content accordingly; so your grandma’s gnarly tablet and your cousin’s awesome new mobile phone can make requests to your portal and receive identical content. This will make everyone happy!
You’re really getting the hang of Liferay’s APIs. Way to go!