Detect Mobile Devices with WURFL in Websites and Mobile Apps

WURFL LogoWhen designing a mobile application or webpage, you may want to know exactly to know what devices access your site or run your application for example to differentiate automatically between desktops, laptops, tablets and smartphones and provide a user interface which is appropriate for a given screen size.

This can be achieved with WURFL (Wireless Universal Resource FiLe), a Device Description Repository (DDR). This software component maps HTTP Request headers to the profile of the HTTP client (Desktop, Mobile Device, Tablet, etc.) and provides a description of the capability of the device that made the request.

WURFL repository is an xml file (wurfl.xml – Direct links to version 2.3.1:  wurfl-2.3.1.zip or wurfl-2.3.1.xml.tar) containing the definition of thousand of devices which can be access using the WURFL APIs.  Several large Internet companies such as Facebook and Google are using WURFL, and ScientiaMobile, the company behind WURFL, claims that it is the most popular DDR by far. Other DDRs include OpenDDR and the maDDR project.

The WURFL API has a dual license model:

  • Affero GPL V3 license. This license requires that all code linked to the WURFL API is made available under a compatible FOSS license even when the code itself is not modified.
  • Commercial License for companies that want to keep their source closed. Commercial licensees also have access to more properties and more frequent database updates.

The XML data is divided in groups (product_info,  display,  playback, etc…) and capabilities within each group. The number of groups available and capabilities reported appear to depend on the device. For example, here’s the record for the Samsung Galaxy Nexus smartphone in wurfl.xml:

<device id=”samsung_galaxy_nexus_ver1″ user_agent=”Mozilla/5.0 (Linux; U; Android 4.0; es-es; Galaxy Nexus Build/IFL10C) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30″ fall_back=”generic_android_ver4″ actual_device_root=”true”>
<group id=”product_info”>
<capability name=”model_name” value=”Galaxy Nexus”/>
<capability name=”brand_name” value=”Samsung”/>
</group>
<group id=”display”>
<capability name=”max_image_width” value=”360″/>
<capability name=”resolution_width” value=”720″/>
<capability name=”resolution_height” value=”1280″/>
<capability name=”max_image_height” value=”640″/>
</group>
</device>

Compared that to the much more detailed record for the Nokia C6-01:

<device id=”nokia_c6_01_ver1″ user_agent=”Mozilla/5.0 (Symbian/3; Series60/5.2 NokiaC6-01/011.010; Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/525 (KHTML, like Gecko) Version/3.0 BrowserNG/7.2.7.2 3gpp-gba” fall_back=”nokia_generic_symbian3″ actual_device_root=”true”>
<group id=”product_info”>
<capability name=”mobile_browser” value=”Nokia BrowserNG”/>
<capability name=”pointing_method” value=”touchscreen”/>
<capability name=”mobile_browser_version” value=”7.2″/>
<capability name=”uaprof” value=”http://nds.nokia.com/uaprof/NC6-01r100.xml”/>
<capability name=”model_name” value=”C6-01″/>
<capability name=”brand_name” value=”Nokia”/>
<capability name=”marketing_name” value=”C6″/>
<capability name=”release_date” value=”2010_september”/>
</group>
<group id=”wml_ui”>
<capability name=”softkey_support” value=”true”/>
<capability name=”table_support” value=”true”/>
</group>
<group id=”markup”>
<capability name=”wml_1_3″ value=”true”/>
</group>
<group id=”display”>
<capability name=”physical_screen_height” value=”71″/>
<capability name=”columns” value=”17″/>
<capability name=”physical_screen_width” value=”40″/>
<capability name=”max_image_width” value=”340″/>
<capability name=”rows” value=”13″/>
<capability name=”resolution_width” value=”360″/>
<capability name=”resolution_height” value=”640″/>
<capability name=”max_image_height” value=”600″/>
</group>
<group id=”image_format”>
<capability name=”jpg” value=”true”/>
<capability name=”gif” value=”true”/>
<capability name=”bmp” value=”true”/>
<capability name=”wbmp” value=”true”/>
<capability name=”png” value=”true”/>
<capability name=”colors” value=”16777216″/>
<capability name=”tiff” value=”true”/>
</group>
<group id=”wta”>
<capability name=”nokia_voice_call” value=”true”/>
<capability name=”wta_phonebook” value=”true”/>
</group>
<group id=”storage”>
<capability name=”max_deck_size” value=”357000″/>
</group>
<group id=”streaming”>
<capability name=”streaming_vcodec_h264_bp” value=”1″/>
<capability name=”streaming_vcodec_mpeg4_sp” value=”0″/>
</group>
<group id=”wap_push”>
<capability name=”wap_push_support” value=”true”/>
</group>
<group id=”mms”>
<capability name=”mms_png” value=”true”/>
<capability name=”mms_max_size” value=”614400″/>
<capability name=”mms_rmf” value=”true”/>
<capability name=”mms_max_width” value=”2048″/>
<capability name=”mms_spmidi” value=”true”/>
<capability name=”mms_max_height” value=”1536″/>
<capability name=”mms_gif_static” value=”true”/>
<capability name=”mms_wav” value=”true”/>
<capability name=”mms_vcard” value=”true”/>
<capability name=”mms_nokia_ringingtone” value=”true”/>
<capability name=”mms_jad” value=”true”/>
<capability name=”mms_midi_monophonic” value=”true”/>
<capability name=”mms_wmlc” value=”true”/>
<capability name=”mms_bmp” value=”true”/>
<capability name=”mms_wbmp” value=”true”/>
<capability name=”mms_jar” value=”true”/>
<capability name=”mms_amr” value=”true”/>
<capability name=”mms_jpeg_baseline” value=”true”/>
</group>
<group id=”sound_format”>
<capability name=”wav” value=”true”/>
<capability name=”nokia_ringtone” value=”true”/>
<capability name=”aac” value=”true”/>
<capability name=”sp_midi” value=”true”/>
<capability name=”amr” value=”true”/>
<capability name=”midi_monophonic” value=”true”/>
</group>
<group id=”bearer”>
<capability name=”max_data_rate” value=”10200″/>
</group>
<group id=”j2me”>
<capability name=”j2me_cldc_1_1″ value=”true”/>
</group>
<group id=”object_download”>
<capability name=”picture_colors” value=”24″/>
</group>
<group id=”playback”>
<capability name=”playback_acodec_aac” value=”lc”/>
<capability name=”playback_acodec_amr” value=”wb”/>
<capability name=”playback_wmv” value=”9″/>
<capability name=”playback_real_media” value=”10″/>
</group>
</device>

The WURFL API is available for Java, PHP, PHP + Database or .NET. There is also a C++ API which is only available to commercial licensees. Beyond those standalone APIs, you can also use WURFL Cloud with both free (up to 5000 requests a month) and paid accounts available. This service allows you to make requests to WURFL servers without having to store the WURFL xml file in your own server and get the latest data available. You can access the WURFL Cloud via Java, PHP or .NET APIs.

I’ve registered for a free WURFL Cloud account, downloaded & installed the PHP Client in cnx-software.com and selected “ux_full_desktop” and “marketing_name” capabilities in order to detect whether the client is a desktop or a mobile device, and for the latter display its name.

Here’s the code (Sorry for the lack of tabulation, WordPress really likes to mess with code):

// Include the WURFL Cloud Client
// You'll need to edit this path
require_once './Client/Client.php';

// Create a configuration object
$config = new WurflCloud_Client_Config();

// Set your WURFL Cloud API Key
$config->api_key = 'xxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

// Create the WURFL Cloud Client
$client = new WurflCloud_Client_Client($config);

// Detect your device
$client->detectDevice();

// Use the capabilities
if ($client->getDeviceCapability('ux_full_desktop')) {
echo "This is a desktop web browser";
} else {
$marketing = $client->getDeviceCapability('marketing_name');
if ($marketing) {
echo "This is a mobile device ($marketing)";
} else {
echo "This is a mobile device";
}
}
?>

Go ahead, you can also try it out. It detects my Nokia C6-01 as a mobile device (good!) and says its marketing name is C6 (somewhat disappointing).

You can visit http://wurfl.sourceforge.net/ for more information.

Share this:

Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress

ROCK 5 ITX RK3588 mini-ITX motherboard
Subscribe
Notify of
guest
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.
0 Comments
oldest
newest
Boardcon Rockchip and Allwinner SoM and SBC products