• About Us
  • Blog
  • Basket
  • Account
  • Sign In
  •  

Core Data Update - Version 3

Version 3 of the Java API utilises static methods to update data. The following code demonstrates this:

package fiftyone.example;

import fiftyone.mobile.detection.AutoUpdate;
import fiftyone.mobile.detection.AutoUpdateException;

public class Command {
		
	public static void main(String[] args) throws IOException, AutoUpdateException {
            
            AutoUpdate.update("YOUR_LICENSE_KEY", "datafile.dat");
        }
}

The update method must be supplied with a valid license key from 51Degrees and a file path to write the data. If the given path already has a data file then the updater will only request data that is newer.

The update may fail if the license key is invalid, the given path is not writable or if the update service cannot be reached (i.e, firewall is blocking the request). The reason for a failure can be seen in the AutoUpdateException that is thrown.

Note that this method does not update any existing dataset or provider objects, they'll need to be rebuilt.

Need Help?

Enable Automatic Updates in the Core Package - Version 2

In the getting started section, you create a Provider using the Reader class. To update data automatically, we will instead use the Factory class. This class creates Providers and is responsible for keeping them up to date.

The Factory class must be given a file path and licence key to get updates:

package console;

import fiftyone.mobile.detection.*;
import java.util.Date;

public class Console {

    public static void main(String[] args) {
        
        Factory factory = new Factory();
        
        try
        {
            factory.initialize("51Degrees.dat", "LICENCE_KEY_HERE");
        }

	// will throw an exception if the data file could not be
        // found and no licence key is supplied
        catch(Exception ex) { }
        
        // this provider will stay current. 
	// the factory can be used to create multiple providers
        Provider provider = factory.getProvider();
        
        // these can be used to see what data is being used
	// this should be 'Premium' if the update worked
        String dataSet = provider.getDataSetName(); 
        Date publishDate = provider.getPublishedDate();
    }
}