51DegreesTM

How to get Signatures/UserAgents from device model

Engineering

10/10/2014 11:30 AM

Java User Agent Development

Using Java

In some cases it may be useful to see what signatures/user agents in your 51Degrees data file are associated with specific content in a selected property.

The following snippet is written in Java and it implements the task in question. Essentially, what happens in this code is: "Hardware Model" properties in the data set are searched for values containing "HTC" or "Desire" or "Desire C". If one of these values is found, the corresponding signatures are fetched and printed.

try { Dataset ds = StreamFactory.create(DATA_FILE); System.out.println("Getting Signatures"); for(Property p : ds.properties) { if (p.getName().equals("HardwareModel")) { for(Value v : p.getValues()) { if (v.getName().contains("HTC") || v.getName().contains("Desire") || v.getName().contains("Desire C")) { for(Signature s : v.getSignatures()) { System.out.println(s.toString()); } } } } } System.out.println("Finished Getting Signatures"); } catch (IOException ex) {

When executed, this snippet produces result similar to the following:

Result of fetching signatures for corresponding HardwareModel from 51Degrees data file.
Result of fetching signatures for corresponding HardwareModel from 51Degrees data file.

This particular example uses the HardwareModel property that is available to Premium and Enterprise users. It can be altered to search for specific strings in any available property.