adrian’s blog

October 10, 2008

Mobile device recognition

Filed under: Software, Web — Tags: , , — Adrian @ 2:16 pm


Nowadays when you create a web site you should also think to the ones accessing it from a mobile device. But how you can know this?
I’m going to show you next a few methods on how you can do this and present the advantages and disadvantage of each one.

WURFL

My favorite method of detecting a mobile device is WURFL. WURFL is an open source database of mobile devices capabilities. Every mobile device is identified by its User-Agent string (you can find it in the HTTP headers) and has associated a list of capabilities grouped into categories. How exactly you can use it in .NET you can see here.
You will also have to consult the X-Device-User-Agent HTTP header because some mobile providers are rewriting the User Agent. And just to be sure that you also recognize Opera Mini (and actually the real device) you can inspect the information in the X-OperaMini-Phone-UA header.
More on the User-Agent HTTP header you can find out on W3C (section 14.43).
I personally like WURFL because it is open source, it tells you more than if the device is mobile or not. The downside is that probably it does not contain info about all the latest mobile devices. But you can easily become a WURFL contributor and submit these info yourself into the WURFL database. Before doing these you should familiarize very well with the WURFL documentation.
I also like that the community is very active and the database contains approximately 7000 devices, making it a very effective method and most importantly with no false positives, unlike the next methods.
Moreover, WURFL has a library for accessing the XML database implemented in Java, .NET and PHP.

UAProf

If WURFL is a devices database, UAProf (User Agent Profile) is a capabilities database for a single device.
The mobile browser could contain an HTTP header usually named x-wap-profile and its value is an URL pointing to the profile described in RDF (see UAProf specs as PDF).
There are some serious downsides to this method:

  • The name of the HTTP header is not always x-wap-profile. It could also be wap-profile or xx-profile, where xx is a number. The Opt header can contain this number.
  • There is no standard regarding the capabilities naming and grouping
  • Not all the devices have UAProf
  • Not all the UAProfs are still available
  • Retrieving and parsing the UAProf can be quite time consuming

Altough you can use an UAProf to define a device in the WURFL database, which should be the preferred way.

Browser.isMobile (.NET dependent)

This is the method that I recommend the less because it is .NET dependent, not quite up-to-date and it doesn’t offer too many information about the device capabilities. Anyway for your reference I include it as well.

if (HttpContext.Current.Request.Browser["IsMobileDevice"] == "true")
{
    // the browser IS a mobile device
}
else
{
    // the browser IS NOT a mobile device
}

.

Next steps

What you do next, after knowing with each type of device are you dealing with, it’s a different story. For sure I wouldn’t recommend you to create two versions of the same page. The best way will be to have only one version and to customize the layout using CSS. Then you definitely have to avoid the “evil” HTML table to build your layout. A lot of current mobile browser don’t handle very good nested tables. Here a method of finding out also the mobile device capabilities (such as screen width and height) will help you in building a better layout. Altough recommended will be to use percentages instead of fixed sizes.

Another way will be to use XSLT to transform the desktop version into the mobile one. Please keep in mind that the transformation should be made on the server side, as almost certain the device will not have this capacity. This is a good approach and you can even transform the page into WML (or even, why not, VoiceXML) but you will have to sacrifice some performance on the server side. This is acceptable as the mobile device version traffic has a lower bandwidth. I already wrote an XSLT server side transformer in .NET and should be as simple and straightforward to implement it in Java as well.

In conclusion, I would recommend to use a combination of the above methods for detecting mobile devices and creating mobile web pages.

Later edit: If you’re also interested in how you can test your mobile web pages please see the next article Testing web mobile pages.

19 Comments »

  1. [...] Tags: Firefox, mobile, mobile device, user agent, Web — Adrian @ 3:28 pm In an earlier post, I was telling you how to detect a mobile device on the server side so you will be able to serve [...]

    Pingback by Testing web mobile pages « Adrian’s Weblog — October 10, 2008 @ 3:28 pm

  2. Did you look into DeviceAtlas? It’s another device database, you get information from public domain sources like UAProf and WURFL, but also from industry players such as Nokia, Vodafone, Argogroup, Volantis, etc.
    You can test devices with our test suite and submit results directly to the database. We have also recently opened a web interface to submit data.

    We also have a .NET API, of course.

    Comment by Andrea Trasatti — October 14, 2008 @ 9:45 am

  3. I like more open source solutions.
    Paid solutions like yours, there are quite many on the market. On the other hand you cannot find too many open source solutions.
    I like WURFL because it is free, open source and it has a very active community. Anyone can become a contributor.

    Comment by Adrian — October 14, 2008 @ 9:59 am

  4. There’s also another option. Instead of specifically detecting mobile devices, you can make the problem simpler by turning this approach upside down.

    See my post on “Not-Device” Detection : http://smartmobtoolkit.wordpress.com/2008/10/16/not-device-detection/

    Over the last 2 years we’ve found this is really reliable and has almost no maintenance issues – even when new model phones are added.

    And we implement it using the completely Open Source mod_rewrite directives which works with both Apache and IIS.

    You could easily do it as a perl/php script…but we find mod_rewrite is faster.

    Comment by robmanson — October 21, 2008 @ 11:03 pm

  5. If it’s only for recognition, your method could be fine, but WURFL offers a list of the device capabilities as well, which could be very useful on creating a better layout.

    Comment by Adrian — October 21, 2008 @ 11:25 pm

  6. I agree WURFL has a detailed definition of device capabilities. However, with our sites and customers we’ve almost never found a real business case for defining specific exceptions on a per device basis.

    We do group devices into;
    - PC
    - iPhone
    - Windows Mobile/High-end Symbian and
    - Plain Old Mobile.

    Within Plain Old Mobile we also sometimes look for specific devices we know have limited memory or screen size.

    Other than that there just doesn’t seem to be enough of an increased benefit in return for the increased complexity of detailed WURFL style capability mapping.

    I’d love to hear some examples from anyone (other than a Telco) who has found a real business benefit from doing this.

    Comment by robmanson — October 23, 2008 @ 12:28 am

  7. Nice site you have

    Comment by Jeryyms — October 23, 2008 @ 7:43 am

  8. A first example that comes to my mind is the image max size when automatically converting the usual images to images for mobile devices.

    Comment by Adrian — October 27, 2008 @ 12:13 pm

  9. If you’re really serious about the customer experience, you need to adapt your pages to all mobiles available. WURFL is a solution that can help you. I have also built my own (not based on wurfl), you can browse handset specs online and you’ll see rapidly that it’s a real mess with no standardisation:

    http://www.mobilemultimedia.be
    There is also a free API to implement server side mobile detecion.

    Comment by Laurent — November 5, 2008 @ 9:39 pm

  10. Unlike your solution, WURFL has more devices and user agents, a very active solution and it is totally FREE.

    Comment by Adrian — November 6, 2008 @ 4:56 pm

  11. you might want to check out handsetdetection.com too. They are offering a free service (which is nice)

    Comment by don — November 17, 2008 @ 3:17 am

  12. It is free, it has a lot of devices in its database, but I will still choose WURFL. Over this solution, the advantages are that it has a very big and active community behind and you can query its entire database offline.

    Comment by Adrian — November 17, 2008 @ 12:11 pm

  13. Max image width is a good example as there is a ridiculous amount of diversity in that attribute. This topic alone can drive designers crazy…and auto transcoding images can lead to varying quality levels. Especially if they are animated gifs.

    We use WURFL as a valuable profiling tool to pre-categorise devices before we start our site planning.

    For max image width we’ve found that using “Not-Device” detection and then sub-grouping based on device type to be really efficient. This means you don’t need to do a profile lookup if it’s not a relevant device.

    For example we have 3 main mobile screen sizes.

    - 90-100px (depending on our target audience).
    - 150px
    - 230px

    A quick statistical analysis using WURFL will show you how efficient that is at cutting down the complexity from thousands of devices with over 130 unique widths … to 3.

    Comment by robmanson — December 2, 2008 @ 3:05 am

  14. Adrian, my solution is free, I’m using a quota based system to avoid being plundered with no “thank you”.

    I don’t know if WURLF has more device, it’s definitely big but size doesn’t matter when you’ve got more than 3000 devices :-)

    I don’t have a huge community, WURFL is the best in this area but I have thousands of real life mobile users using my API every month, it’s fairly enough to add new devices every day.

    Comment by Laurent — December 17, 2008 @ 11:59 am

  15. [...] If you’re interested in recognizing user’s mobile device on the server side, see my other article: Mobile device recognition. [...]

    Pingback by Mobile web « Adrian’s Weblog — January 10, 2009 @ 6:48 pm

  16. [...] Next, I will present a short and practical solution, implemented as an aspx page. The page is taking only one parameter (i), which is the URL of the original image, downloads it, resizes it and sends it back to the client. This can also be implemented as an HTTP filter as well: every time an image is requested, it gets the original image, resizes it and pushes it into the response. The advantage as a page is that you can process this way, even images from other servers. As for how to recognize the user mobile device, we will use my favorite, WURFL. For more information see Mobile device recognition. [...]

    Pingback by Resize images for mobile web « Adrian’s Weblog — January 13, 2009 @ 4:12 pm

  17. You might also be interested in the two examples of “Not-Device Detection” code we’ve recently posted:

    Apache config
    http://smartmobtoolkit.wordpress.com/2009/01/25/not-device-detection-example-code/

    Javascript, perl and php
    http://smartmobtoolkit.wordpress.com/2009/01/26/not-device-detection-javascript-perl-and-php-code/

    Comment by robmanson — January 27, 2009 @ 6:46 pm

  18. Hi,
    I have published the last version of “Apache Mobile Filter”, this open source project have, in the first six months, more than 600 downloads from sourceforge and I think the same from CPAN.

    The Apache Mobile Filter allows you to access WURFL from any programming language, not just Java and php that is traditionally used for dynamic mobile web sites.

    The module detects the mobile device and passes the WURFL capabilities on to the other web application as environment variables. It can also be used to resize images on the fly to adapt to the screen size of the mobile device.

    Try it and let me know your opinion.

    For more info: http://www.idelfuschini.it/it/apache-mobile-filter-v2x.html

    Demo: http://apachemobilefilter.nogoogle.it/php_test.php

    Comment by Idel — July 7, 2009 @ 8:42 pm

  19. Great Post.

    Thank you for the info.

    Comment by electroniccigarettes — September 17, 2009 @ 10:07 pm


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.