The DeviceAtlas DeviceApi documentation
|
Used to load the recognition tree and perform lookups of all properties, or get individual properties. Typical usage is as follows: More...
Static Public Member Functions | |
static Hashtable | GetTreeFromString (string json) |
Returns a loaded JSON tree from a string of JSON data. This will also initialise the changeable property recognition. More... | |
static Hashtable | GetTreeFromString (string json, bool includeChangeableUserAgentProperties) |
Returns a loaded JSON tree from a string of JSON data. More... | |
static Hashtable | GetTreeFromFile (string filename) |
Returns a tree from a JSON file, If it has been previously loaded then the version from the static cache will be returned. To reload from file call getTreeFromFile() with reload set to true. More... | |
static Hashtable | GetTreeFromFile (string filename, bool reload) |
Returns a tree from a JSON file. The loaded tree is stored in a static cache to avoid multiple reloads if this method is repeatedly called. To reload from the JSON file set reload to true. More... | |
static Hashtable | GetTreeFromFile (string filename, bool reload, bool includeChangeableUserAgentProperties) |
Returns a tree from a JSON file. The loaded tree is stored in a static cache to avoid multiple reloads if this method is repeatedly called. To reload from the JSON file set reload to true. More... | |
static string | GetTreeGeneration (Hashtable tree) |
Get the generation date for this tree. More... | |
static int | GetTreeGenerationAsTimestamp (Hashtable tree) |
Get the generation date for this tree as a UNIX timestamp. More... | |
static int | GetApiRevision () |
Returns the revision number of this API More... | |
static int | GetTreeRevision (Hashtable tree) |
Returns the revision number of the tree More... | |
static Hashtable | ListProperties (Hashtable tree) |
Returns a HashMap of known property names available for the user agents in this file, with their data type names More... | |
static Hashtable | GetProperties (Hashtable tree, string userAgent) |
Returns a HashMap of known properties (as strings) for the user agent More... | |
static Hashtable | GetProperties (Hashtable tree, string userAgent, string cookie) |
Returns a HashMap of known properties merged with properties from the client side JavaScript. The client side JavaScript sets a cookie with collected properties. The contents of this cookie must be passed to this method for it to work. The client properties over-ride any properties discovered from the main JSON data file. More... | |
static Hashtable | GetPropertiesAsTyped (Hashtable tree, string userAgent) |
Returns a HashMap of known properties (as typed) for the user agent More... | |
static Hashtable | GetPropertiesAsTyped (Hashtable tree, string userAgent, string cookie) |
Returns a HashMap of known properties merged with properties from the client side JavaScript. The client side JavaScript sets a cookie with collected properties. The contents of this cookie must be passed to this method for it to work. The client properties over-ride any properties discovered from the main JSON data file. More... | |
static string | GetProperty (Hashtable tree, string userAgent, string property) |
Returns a value for the named property for this user agent More... | |
static string | GetProperty (Hashtable tree, string userAgent, string cookie, string property) |
Returns a value for the named property for this user agent More... | |
static string | GetPropertyAsString (Hashtable tree, string userAgent, string property) |
Strongly typed property accessor. Returns a string property (or throws an exception if the property is actually of another type) More... | |
static string | GetPropertyAsString (Hashtable tree, string userAgent, string cookie, string property) |
Strongly typed property accessor. Returns a string property (or throws an exception if the property is actually of another type) More... | |
static bool | GetPropertyAsBoolean (Hashtable tree, string userAgent, string property) |
Strongly typed property accessor. Returns a boolean property (or throws an exception if the property is actually of another type) More... | |
static bool | GetPropertyAsBoolean (Hashtable tree, string userAgent, string cookie, string property) |
Strongly typed property accessor. Returns a boolean property (or throws an exception if the property is actually of another type) More... | |
static int | GetPropertyAsInteger (Hashtable tree, string userAgent, string property) |
Strongly typed property accessor. Returns an integer property (or throws an exception if the property is actually of another type) More... | |
static int | GetPropertyAsInteger (Hashtable tree, string userAgent, string cookie, string property) |
Strongly typed property accessor. Returns an integer property (or throws an exception if the property is actually of another type) More... | |
static string | GetPropertyAsDate (Hashtable tree, string userAgent, string property) |
static string | GetPropertyAsDate (Hashtable tree, string userAgent, string cookie, string property) |
Used to load the recognition tree and perform lookups of all properties, or get individual properties. Typical usage is as follows:
HashTable tree = Api.GetTreeFromFile("datafile.json"); HashTable prps = Api.GetProperties(tree, "Nokia6680..."); Object prop = Api.GetProperty(tree, "Nokia6680...", "displayWidth");
Note that you should normally use the user-agent that was received in the device's HTTP request. In a JSP environment, you would do this as follows: String ua = request.getHeader("User-Agent"); int displayWidth = Api.getPropertyAsInteger(tree, ua, "displayWidth");
(Also note the use of the strongly typed property accessor)
In some contexts, the user-agent you want to recognise may have been provided in a different header. Opera's mobile browser, for example, makes requests via an HTTP proxy, which rewrites the headers. in that case, the original device's user-agent is in the "X-OperaMini-Phone-UA" header, and the following code could be used:
String ua; String operaHeader = "X-OperaMini-Phone-UA"; if (request.getHeader(operaHeader) != null) { ua = request.getHeader(operaHeader); } else { ua = request.getHeader("User-Agent"); } int displayWidth = Api.getPropertyAsInteger(tree, ua, "displayWidth");
See here for more information: https://deviceatlas.com/resources/side-loaded-browser-handling
Client side properties can be collected and merged into the results by using the DeviceAtlas Javascript detection file. The results from the client side are sent to the server inside a cookie. The contents of this cookie can be passed to the DeviceAtlas getProperty and getProperties methods. The client side properties over-ride any data file properties and also serve as an input into additional logic to determine other properties such as the iPhone models that are otherwise not detectable. The following code shows how this can be done in a JSP:
String userAgent = request.getHeader("User-Agent");
// get the cookie containing the client side properties String cookieContents = null; Cookie[] cookies = request.getCookies(); if(cookies != null) { for(int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; if(cookie.getName().equals("DAPROPS")) { cookieContents = cookie.getValue(); } } }
HashMap properties = Api.getPropertiesAsTyped(tree, userAgent, cookieContents);
<deprecated>Use "Mobi.Mtld.DA.Device.DeviceApi" instead see
</deprecated>
|
inlinestatic |
Returns the revision number of this API
|
inlinestatic |
Returns a HashMap of known properties (as strings) for the user agent
tree | previously generated HashMap tree |
userAgent | The device's User-Agent header string |
|
inlinestatic |
Returns a HashMap of known properties merged with properties from the client side JavaScript. The client side JavaScript sets a cookie with collected properties. The contents of this cookie must be passed to this method for it to work. The client properties over-ride any properties discovered from the main JSON data file.
tree | previously generated HashMap tree |
userAgent | the device's User-Agent header string |
cookie | the contents of the cookie containing the client side properties |
ClientPropertiesException | See
|
|
inlinestatic |
|
inlinestatic |
Returns a HashMap of known properties merged with properties from the client side JavaScript. The client side JavaScript sets a cookie with collected properties. The contents of this cookie must be passed to this method for it to work. The client properties over-ride any properties discovered from the main JSON data file.
tree | previously generated HashMap tree |
userAgent | the device's User-Agent header string |
cookie | the contents of the cookie containing the client side properties |
ClientPropertiesException | See
|
|
inlinestatic |
Returns a value for the named property for this user agent
tree | previously generated HashMap tree |
userAgent | the device's User-Agent header string |
property | the name of the property to return |
InvalidPropertyException | See
|
UnknownPropertyException | See
|
|
inlinestatic |
Returns a value for the named property for this user agent
tree | previously generated HashMap tree |
userAgent | the device's User-Agent header string |
cookie | the contents of the cookie containing the client side properties |
property | the name of the property to return |
InvalidPropertyException | See
|
UnknownPropertyException | See
|
|
inlinestatic |
Strongly typed property accessor. Returns a boolean property (or throws an exception if the property is actually of another type)
<seealso cref= #getProperty(HashMap,String,String)
tree | previously generated HashMap tree |
userAgent | the device's User-Agent header string |
property | the name of the property to return |
IncorrectPropertyTypeException | See
|
InvalidPropertyException | See
|
UnknownPropertyException | See
|
ClientPropertiesException | See
|
|
inlinestatic |
Strongly typed property accessor. Returns a boolean property (or throws an exception if the property is actually of another type)
<seealso cref= #getProperty(HashMap,String,String)
tree | previously generated HashMap tree |
userAgent | the device's User-Agent header string |
cookie | the contents of the cookie containing the client side properties |
property | the name of the property to return |
IncorrectPropertyTypeException | See
|
InvalidPropertyException | See
|
UnknownPropertyException | See
|
ClientPropertiesException | See
|
|
inlinestatic |
Strongly typed property accessor. Returns an integer property (or throws an exception if the property is actually of another type)
<seealso cref= #getProperty(HashMap,String,String)
tree | previously generated HashMap tree |
userAgent | the device's User-Agent header string |
property | the name of the property to return |
IncorrectPropertyTypeException | See
|
InvalidPropertyException | See
|
UnknownPropertyException | See
|
ClientPropertiesException | See
|
|
inlinestatic |
Strongly typed property accessor. Returns an integer property (or throws an exception if the property is actually of another type)
<seealso cref= #getProperty(HashMap,String,String)
tree | previously generated HashMap tree |
userAgent | the device's User-Agent header string |
cookie | the contents of the cookie containing the client side properties |
property | the name of the property to return |
IncorrectPropertyTypeException | See
|
InvalidPropertyException | See
|
UnknownPropertyException | See
|
ClientPropertiesException | See
|
|
inlinestatic |
Strongly typed property accessor. Returns a string property (or throws an exception if the property is actually of another type)
<seealso cref= #getProperty(HashMap,String,String)
tree | previously generated HashMap tree |
userAgent | the device's User-Agent header string |
property | the name of the property to return |
IncorrectPropertyTypeException | See
|
InvalidPropertyException | See
|
UnknownPropertyException | See
|
ClientPropertiesException | See
|
|
inlinestatic |
Strongly typed property accessor. Returns a string property (or throws an exception if the property is actually of another type)
<seealso cref= #getProperty(HashMap,String,String)
tree | previously generated HashMap tree |
userAgent | the device's User-Agent header string |
cookie | the contents of the cookie containing the client side properties |
property | the name of the property to return |
IncorrectPropertyTypeException | See
|
InvalidPropertyException | See
|
UnknownPropertyException | See
|
ClientPropertiesException | See
|
|
inlinestatic |
Returns a tree from a JSON file, If it has been previously loaded then the version from the static cache will be returned. To reload from file call getTreeFromFile() with reload set to true.
Some properties cannot be known before runtime and can change from user-agent to user-agent. The most common of these are the OS Version and the Browser Version. This API is able to dynamically detect these changing properties but introduces a small overhead to do so. To disable returning these extra properties set includeChangeableUserAgentProperties to false.
filename | the location of the file to read in. Use an absolute path name to be sure of success if the current working directory is not clear. |
JsonException |
|
IOException | There was an unknown error reading the JSON file |
|
inlinestatic |
Returns a tree from a JSON file. The loaded tree is stored in a static cache to avoid multiple reloads if this method is repeatedly called. To reload from the JSON file set reload to true.
Some properties cannot be known before runtime and can change from user-agent to user-agent. The most common of these are the OS Version and the Browser Version. This API is able to dynamically detect these changing properties but introduces a small overhead to do so. To disable returning these extra properties call getTreeFromFile() with includeChangeableUserAgentProperties set to false.
filename | the location of the file to read in. Use an absolute path name to be sure of success if the current working directory is not clear. |
reload | set true to reload regardless of static cache |
JsonException |
|
IOException | There was an unknown error reading the JSON file |
|
inlinestatic |
Returns a tree from a JSON file. The loaded tree is stored in a static cache to avoid multiple reloads if this method is repeatedly called. To reload from the JSON file set reload to true.
Some properties cannot be known before runtime and can change from user-agent to user-agent. The most common of these are the OS Version and the Browser Version. This API is able to dynamically detect these changing properties but introduces a small overhead to do so. To disable returning these extra properties set includeChangeableUserAgentProperties to false.
filename | the location of the file to read in. Use an absolute path name to be sure of success if the current working directory is not clear. |
reload | set true to reload regardless of static cache |
includeChangeableUserAgentProperties | Also detect changeable user-agent properties |
JsonException |
|
IOException | There was an unknown error reading the JSON file |
|
inlinestatic |
Returns a loaded JSON tree from a string of JSON data. This will also initialise the changeable property recognition.
Some properties cannot be known before runtime and can change from user-agent to user-agent. The most common of these are the OS Version and the Browser Version. This API is able to dynamically detect these changing properties but introduces a small overhead to do so. To disable returning these extra properties call getTreeFromString() with includeChangeableUserAgentProperties set to false.
This method does not use the built in static cache.
json | The JSON HashMap object |
JsonException |
|
inlinestatic |
Returns a loaded JSON tree from a string of JSON data.
Some properties cannot be known before runtime and can change from user-agent to user-agent. The most common of these are the OS Version and the Browser Version. This API is able to dynamically detect these changing properties but introduces a small overhead to do so. To disable returning these extra properties set includeChangeableUserAgentProperties to false.
This method does not use the built in static cache.
json | The string of json data. |
includeChangeableUserAgentProperties | Also detect changeable user-agent properties |
JsonException |
|
|
inlinestatic |
Get the generation date for this tree.
tree |
|
inlinestatic |
Get the generation date for this tree as a UNIX timestamp.
tree |
|
inlinestatic |
Returns the revision number of the tree
tree | previously generated HashMap tree |
|
inlinestatic |
Returns a HashMap of known property names available for the user agents in this file, with their data type names
tree | previously generated HashMap tree |