How to: Create, Load, Unload or delete custom configuration profiles, and optionally associate them to application ProfileRules with Datalogic SDK

With the introduction of the Datalogic SDK 1.32 (see SDK - Supported devices Table), all Datalogic devices allow different sets of configuration parameters to be defined, which can be manually loaded and downloaded by an application as required via the Datalogic SDK or associated with specific ProfileRules for the system to automatically apply them as soon as a specific application comes to the foreground.

The easiest way for a use to associate a specific configuration profile with an app is to use the Scan2Deploy Studio tool to create create an “Application Policy” as described in the discussion: How to: create Application Policies to switch between Multiple Scanner profiles on a single device.

To manually create, upload, download or delete a configuration profile by code, an application must rely on the com.datalogic.device.configuration.ProfileManager class.

A profile is identified by a symbolic name that must be unique on the device
A profile is a set of properties with their value. The list of all the available properties is list of the IDs defined by the com.datalogic.device.configuration.PropertyID class:

Create a profile:

  1. Obtain an instance of ProfileManager with ProfileManager(Context).
  2. Create an HashMap and add it the couples {PropertyID,value} to be set applying the profile.
  3. Create the profile calling createProfile(String, HashMap, String, PersistenceType).
 ProfileManager pm = new ProfileManager(this);
 HashMap map = new HashMap();
 map.put(PropertyID.CODE128_ENABLE, "true");  // BooleanProperty
 map.put(PropertyID.CODE128_LENGTH2, "10"); // NumericProperty
 map.put(PropertyID.CODE128_GS1_USER_ID, String.format ("\\u%04x", (int)'a')); // CharacterProperty
 map.put(PropertyID.CODE128_LENGTH_CONTROL, LengthControlMode.ONE_FIXED.toString()); // EnumProperty
 map.put(PropertyID.LABEL_PREFIX, "ABC"); // TextProperty
 pm.createProfile("profile_128.json", 
                  map, 
                  "enable code128, disable datamatrix", 
                  PersistenceType.ENTERPRISE_RESET_PERSISTENT);

Manually load a profile:

  1. Obtain an instance of ProfileManager with ProfileManager(Context).
  2. Load the profile calling loadProfile(String).
 ProfileManager pm = new ProfileManager(this);
 pm.loadProfile("profile_1.json");

Add a rule to automatically load a profile when an app comes to the foreground:

  1. Obtain an instance of ProfileManager with ProfileManager(Context).
  2. Create a StringBuffer and initialize it with the preferred identifier to be used to register the rule.
  3. Create the rule calling addProfileRule(StringBuffer, String, String, ArrayList).
 ProfileManager pm = new ProfileManager(this);
 StringBuffer rule1_name = new StringBuffer("rule_1");
 pm.addProfileRule(rule1_name,
                   "profile_1.json", 
                   "com.datalogic.testprofile1", 
                   new ArrayList());

For more detailed information on the ProfileManager class 's capabilities and for more examples on how to List all the Profiles and Rules saved on the system, Load or Unload a profile, Delete a profile or a rule, and many other, check the com.datalogic.device.configuration.ProfileManager, profiles and ProfilesRules page on the of the Datalogic SDK reference documentation: SDK - ProfileManager Class.

Simone Callegari
Datalogic Mobile Products Specialist - L3 SW Engineer