fiftyone.device.example.illustration
Class GettingStarted

java.lang.Object
  extended by fiftyone.device.example.illustration.GettingStarted
All Implemented Interfaces:
Closeable

public class GettingStarted
extends Object
implements Closeable

Getting started example of using 51Degrees device detection. The example shows how to:

  1. Instantiate 51Degrees detection provider
      
          provider = new Provider(StreamFactory.create(
          Shared.getLitePatternV32(), false));
      
      
  2. Pass in a single HTTP User-Agent header
      
          Match match = provider.match(userAgent);
      
      
  3. Extract the value of the IsMobile Property
      
          match.getValues("IsMobile").toString();
      
      
main assumes it is being run with a working directory at root of project or of this module.


Field Summary
protected  String desktopUserAgent
           
protected  String mediaHubUserAgent
           
protected  String mobileUserAgent
           
protected  Provider provider
           
 
Constructor Summary
GettingStarted()
          Initialises the device detection Provider with the included Lite data file.
 
Method Summary
 void close()
          Closes the Dataset by releasing data file readers and freeing the data file from locks.
 String detect(String userAgent)
          Matches provided User-Agent string and returns IsMobile property value.
static void main(String[] args)
          Main entry point for this example.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

provider

protected final Provider provider

mobileUserAgent

protected final String mobileUserAgent
See Also:
Constant Field Values

desktopUserAgent

protected final String desktopUserAgent
See Also:
Constant Field Values

mediaHubUserAgent

protected final String mediaHubUserAgent
See Also:
Constant Field Values
Constructor Detail

GettingStarted

public GettingStarted()
               throws IOException
Initialises the device detection Provider with the included Lite data file. For more data see: compare data options

Throws:
IOException - can be thrown if there is a problem reading from the provided data file.
Method Detail

detect

public String detect(String userAgent)
              throws IOException
Matches provided User-Agent string and returns IsMobile property value. Detection initiated by invoking Provider.match(java.lang.String). Detection results are then stored in the Match object and can be accessed using the Match.getValues("PropertyName") method.

Parameters:
userAgent - HTTP User-Agent string.
Returns:
String with value for IsMobile property for a given User-Agent.
Throws:
IOException - if there is a problem accessing the data file.

main

public static void main(String[] args)
                 throws IOException
Main entry point for this example. For each of the User-Agents defined in this class:
  1. invokes detect(java.lang.String) method; and
  2. prints results.
Result in this case will be either True or False, depending on whether the User-Agent belongs to a mobile device or a non-mobile device.

Parameters:
args - command line arguments, not used.
Throws:
IOException - if there is a problem accessing the data file that will be used for device detection.

close

public void close()
           throws IOException
Closes the Dataset by releasing data file readers and freeing the data file from locks. This method should only be used when the Dataset is no longer required, i.e. when device detection functionality is no longer required, or the data file needs to be freed.

Specified by:
close in interface Closeable
Throws:
IOException - if there is a problem accessing the data file.


Copyright © 2017 51Degrees. All rights reserved.