IBM Skip to main content
Search for:   within 
      Search help  
     IBM home  |  Products & services  |  Support & downloads   |  My account

developerWorks > Wireless | Java technology
Tips & tricks: Mobile device detection
64KBe-mail it!
Why device detection?
Available methods
In conclusion
About the author
Rate this article
Related content:
Previous columns
dW newsletters
dW Subscription
(CDs and downloads)
Application publishing

Level: Introductory

Roman Vichr ( device detection)
Senior Architect, Etensity
1 June 2002

This week, Roman discusses wireless device detection and its importance in application publishing.

Why device detection?
There is a wide selection of wireless devices with distinguishing capabilities, displays, and functionality. In order to "publish" the application, meaning a specific data display for each device, a detection process is necessary. The following figure illustrates the device detection process:

Device detection
Device detection

Available methods
With the commonly used architectures for WML communicating over the HTTP protocol, you can take advantage of the HTTP header, which will contain information about the targeted device itself (see Better mobile interfaces, developerWorks, May 2002). The presentation can be then rendered not only on the devices bases, but also specifically for multiple browsers, voice browsers, and Web browsers.

Usually, the automatic browser detection available on many HTTP servers (including the OS/400 Web server V4R3 and later) can be used to determine the device. Secondly, this can be done dynamically in a Java-based Web server application using a servlet, JavaBean, or Java Server Page (JSP). In the case of an MS IIS server, it would probably be MS ActiveX component or ASP page. That does not exclude other application servers based on other languages, like PHP, from using a similar architectural approach.

First, we can detect every WAP-enabled device based on what it sends as an HTTP request, according to its HTTP header parameter HTTP_ACCEPT. For that reason we need to make sure that our server is configured to accept the following MIME formats:

  • text/vnd.wap.wml for .wml files (WML source files)
  • application/vnd.wap.wmlc for .wmlc files (WML compiled files)
  • text/vnd.wap.wmlscript for .wmls files (WMLScript source files)
  • application/vnd.wap.wmlscriptc for .wmlsc files (WMLScript compiled files)
  • image/vnd.wap.wbmp for .wbmp files (wireless bitmaps)

To detect the type of browser by the device, we would search for a specific string; for instance, "Windows CE," the HTTP request parameter HTTP_USER_AGENT for IIS-based or USER_AGENT variable in a Java-based solution.

In Java code we would use the following:

public void doGet (HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
  String userWmlAgent = req.getHeader("User-Agent");
        String device = null; 
        out = res.getWriter(); }

The servlet determined the device type by checking the User-Agent variable in the HTTP header and would store it for later use in a variable.

Consequently, you can test the userWmlAgent variable for a "Wap" or "WAP" string to set a specific MIME type in the response, or test for "Web" or "PALM" to set specific MIME type and device type for those also.

if ((userWmlAgent.indexOf("Wap")>= 0) | (userWmlAgent.indexOf("WAP")>= 0 )) {
    res.setContentType("text/vnd.wap.wml; charset=ISO-8859-1");
   device = "WML";
  if ((userWmlAgent.indexOf("Web")>= 0) | (userWmlAgent.indexOf("Palm")>= 0)
|   userWmlAgent.indexOf("Hand")>= 0)){ 
    res.setContentType("text/html; charset=ISO-8859-1");
         device = "LHTML";
".. /// and you can continue to search for other types of devices

In the case of an ASP server we would use something like this:

If (InStr(Request.ServerVariables("HTTP_USER_AGENT"), "Windows CE")) Then
End If

The transformation engine or component would then take the input of the detection components and modify the presentation for the output using xHTML or XSLT, depending on the desired look and feel criteria of a given device.

In conclusion
To make the presentation of content and data in enterprise suitable for the spectrum of various devices seems not to be an easy task, but device detection and transformation will provide you with such capability. Device detection itself will become even more important when providing network services to wireless devices in pervasive computing.


About the author
Roman Vichr is Senior Architect at Etensity, an e-commerce and EAI consulting company. His latest interest includes expanding databases into wireless technology, after focusing on database management for client/server and Web applications development over the past nine years. His background is in fiberoptics, culminating in a Ph.D. in the field from Prague's Institute of Chemical Technology in 1992. You can reach him at

64KBe-mail it!

What do you think of this document?
Killer! (5) Good stuff (4) So-so; not bad (3) Needs work (2) Lame! (1)


developerWorks > Wireless | Java technology
  About IBM  |  Privacy  |  Terms of use  |  Contact