Device Profile API

Introduction
Sample
Parameters
Details
Examples

Introduction

The Device Profile API matches a device based on the request useragent and returns the matched device's capabilities in XML format.

Sample

Device Profile usage urls must be in the following format:

http://www.mobileelements.com/DeviceProfileAPI?key=00000000000000000000000000000000

This example will match on the http request useragent and return the capabilities for that device:

<device Vendor="Sanyo" Model="MM5600"> <display_width>234</display_width> <display_height>261</display_height> <display_columns>18</display_columns> <display_rows>11</display_rows> <image_colors>262144</image_colors> <image_format_bmp>False</image_format_bmp> <image_format_gif>False</image_format_gif> <image_format_gif_animated>False </image_format_gif_animated> <image_format_png>True</image_format_png> <image_format_jpg>True</image_format_jpg> <sound_format_wav>False</sound_format_wav> <sound_format_aac>False</sound_format_aac> <sound_format_mp3>False</sound_format_mp3> <sound_format_amr>False</sound_format_amr> <sound_format_midi_monophonic>True </sound_format_midi_monophonic> <sound_format_midi_polyphonic>True </sound_format_midi_polyphonic> <supports_js>True</supports_js> <supports_tables>True</supports_tables> <supports_cookies>True</supports_cookies> <font_size/> <click_to_call_xhtml>tel:</click_to_call_xhtml> <click_to_email_xhtml>mailto:</click_to_email_xhtml> <click_to_mms_xhtml/> <click_to_sms_xhtml/> </device>
The API is intended to be called from server side code. Examples in different languages can be found below.

Parameters

Parameters are separated with the ampersand (&) character. You can specify the parameters in any order.

Parameter Description Required?
key Your user key (view My Account to retrieve your key) Yes
ua The useragent string to override No (Default is the http request useragent)

Details

The device profile api will use the current http request headers to match the device viewing the stylesheet. If the "ua" parameter is supplied, it will override the useragent supplied in the http headers and the input parameter value will be used to match the device instead.

The device profile api is designed to best match the incoming request and find out what handset has generated the incoming request, it will then send back all the details that are stored for that device.

Examples

PHP

There are many different ways to read XML in PHP. The example below uses regexes to access the device data, since this method requires no additional libraries and should work on a majority of PHP setups. Two other common methods are using either SAX or DOM to read the XML.

<?php $xml = ""; $f = fopen( "http://www.mobileelements.com/DeviceProfileApi?key=00000000000000000000000000000000&ua=iphone", "r" ); while( $data = fread( $f, 4096 ) ) { $xml .= $data; } fclose( $f ); preg_match_all( "/\<device (.*?)\>(.*?)\<\/device\>/s", $xml, $myDevice ); preg_match_all( "/Vendor=\"(.*?)\"/", $myDevice[1][0], $Vendor ); preg_match_all( "/Model=\"(.*?)\"/", $myDevice[1][0], $Model ); preg_match_all( "/\<display_width\>(.*?)\<\/display_width\>/", $myDevice[2][0], $DisplayWidth ); echo("Matched: ".$Vendor[1][0]." ".$Model[1][0]."<br />\n" ); echo("DisplayWidth: ".$DisplayWidth[1][0] ); ?>

C#

using System; using System.Xml; public class MobileInternetToolkit { public static void Main(string[] args) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("http://www.mobileelements.com/DeviceProfileApi?key=00000000000000000000000000000000&ua=iphone"); string vendor = xmlDoc.DocumentElement.Attributes["Vendor"].Value; string model = xmlDoc.DocumentElement.Attributes["Model"].Value; string displayWidth = xmlDoc.DocumentElement.SelectSingleNode("display_width").InnerText; Console.WriteLine(string.Format("Matched: {0} {1}", vendor, model)); Console.WriteLine(string.Format("DisplayWidth: {0}", displayWidth)); } }

Java

import java.io.IOException; import javax.xml.parsers.*; import javax.xml.xpath.*; import org.w3c.dom.*; import org.xml.sax.SAXException; public class MobileInternetToolkit { public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException { DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(true); // never forget this! DocumentBuilder builder = domFactory.newDocumentBuilder(); Document doc = builder.parse("http://www.mobileelements.com/DeviceProfileApi?key=00000000000000000000000000000000&ua=iphone"); XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); XPathExpression expr1 = xpath.compile("//device/@Vendor"); XPathExpression expr2 = xpath.compile("//device/@Model"); XPathExpression expr3 = xpath.compile("//device/display_width/text()"); String vendor = expr1.evaluate(doc); String model = expr2.evaluate(doc); String displayWidth = expr3.evaluate(doc); System.out.println("Matched: " + vendor + " " + model); System.out.println("DisplayWidth: " + displayWidth); } } Back to Top