Java Client 1.1

-Include the following 2 maven dependencies:

   1     <dependency>
   2       <groupId>org.apache.devicemap</groupId>
   3       <artifactId>devicemap-client</artifactId>
   4       <version>1.1.0</version>
   5     </dependency>
   6     <dependency>
   7       <groupId>org.apache.devicemap</groupId>
   8       <artifactId>devicemap-data</artifactId>
   9       <version>1.0.1</version>
  10     </dependency>

NOTE: If using LoaderOption URL or FOLDER, you can drop the above devicemap-data dependency.

-Include the following Java code:

   1   //get client using JAR data source
   2   DeviceMapClient client = DeviceMapFactory.getClient(LoaderOption.JAR);
   3 
   4   //get client using data from a URL
   5   //DeviceMapClient client = DeviceMapFactory.getClient(LoaderOption.URL, "http://devicemap-vm.apache.org/data/latest");
   6 
   7   //get client using data from a local filesystem
   8   //DeviceMapClient client = DeviceMapFactory.getClient(LoaderOption.FOLDER, "/some/path/devicemap/latest/devicedata");
   9 
  10   String userAgent = "Mozilla/5.0 (Linux; U; Android 2.2; en; HTC Aria A6380 Build/ERE27) AppleWebKit/540.13+ (KHTML, like Gecko) Version/3.1 Mobile Safari/524.15.0";
  11 
  12   //classify the userAgent
  13   Device device = client.classifyDevice(userAgent);
  14 
  15   System.out.println("Device detected: " + device.getId());
  16 
  17   //iterate thru the attributes
  18   for (String attr : device.getAttributes().keySet()) {
  19       System.out.println(attr + ": " + device.getAttribute(attr));
  20   }

JavaClient1 (last edited 2014-12-23 17:50:17 by rezan)