Step by Step Guide for Netbeans
These instructions assume you have Netbeans, JDK and JRE 1.6 or later installed and configured for your system.
- Download the latest Java package from Sourceforge
- Unzip to your preferred project directory
- Add reference to the 51Degrees core JAR file to your project by right clicking the 'Libraries' and selecting 'Add JAR/Folder' option.
You should see a file selection window. Navigate to the directory 'dist' directory and sselect the 'core' JAR file:
You should see the 'core' package in the list of libraries.
- 4.The code below demonstrates how to initialize the API and supply it with the device data file as well as how to perform the match and retrieve the results
import fiftyone.mobile.detection.Match ; import fiftyone.mobile.detection.Provider ; import fiftyone.mobile.detection.factories.StreamFactory ; import java.io.IOException ; public class GettingStartedNetbeans { public static void main ( String [] args ) throws IOException { // FiftyOne Provider object - used to access data and perform match. Provider provider ; // Path to FiftyOne device data file. String datFile = "path\\to\\data_file.dat" ; // User agent string of the device in question. String userAgent = "Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en) " + "AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.1.0.346 " + "Mobile Safari/534.11+" ; // Initialise provider with the data file to use. // 'false' flag indicates the data file is not temporary. provider = new Provider ( StreamFactory . create ( datFile , false )); // Match object contains results of detection. Match match = provider . match ( userAgent ); // Fetch specific property, in this case 'IsMobile'. boolean isMobile = match . getValues ( "IsMobile" ). toBool (); // Implement some logic based on detection results. if ( isMobile ) System . out . println ( "This device is mobile." ); else System . out . println ( "This device is not mobile." ); System . out . println ( match . getValues ( "BrowserName" )); } }
Once the program executes you should see that the user agent in this example is a mobile device using the Blackberry browser.