Set Default Profile

DataWedge 14.1

SET_DEFAULT_PROFILE

Used to designate a specified Profile as the default Profile. This functions only if the specified Profile exists and is not already associated with an application. While a Profile can be associated with multiple applications, each application can only be associated with a single Profile. Due to DataWedge's automatic Profile switching when an activity is paused, Zebra recommends to call this API from the activity's onResume method.

Zebra recommends creating a Profile that accommodates all applications/activities not associated with DataWedge, which would otherwise default to Profile0, to prevent unintended configuration changes. This helps maintain consistent scanner-device settings across different apps.

About Default Profile

Profile0 is a generic Profile that automatically applies to any app that comes to the foreground without a DataWedge association. While all parameters of Profile0 can be edited, its association cannot be altered. This means DataWedge can manipulate input, processing and output settings for Profile0 but cannot assign it to any specific foreground application. This enables DataWedge to direct output to any unassociated app that becomes active in the foreground.

Profile0 can be disabled to ensure DataWedge only sends output data to applications associated with user-defined Profiles. For example, by creating a Profile, associating it with a specific application, and disabling Profile0, DataWedge will only send data to the specified application, adding an extra layer of security.

Usage Scenario

Consider a launcher application with a list of apps that a user can launch, none of which are associated with a DataWedge Profile. The setDefaultProfile method can be used to associate a Profile with any app selected by the user; otherwise, Profile0 is used. When the user-selected app is launched, DataWedge's auto-Profile switching will switch to the newly specified Profile.

If the launched app already has an associated DataWedge Profile, the setDefaultProfile method call is ignored, and its previously specified Profile is loaded. Upon returning control to the Launcher application, resetDefaultProfile can be used to reset the default Profile.

In another scenario, if Profile0 is the default Profile and configured to use the camera as the barcode scanner, and only the Browser application is configured for this setup, DataWedge will consistently use the camera to scan and input the acquired data into the Browser as expected. However, if another application is launched that switches to a Profile using a different scanner, the Browser application, which defaults to Profile0, may unexpectedly switch to the new scanner for subsequent scans. To ensure the Browser continues using the camera for barcode scanning in this scenario, create a Profile that specifies the camera as the barcode scanner and associate it with the Browser.

Function Prototype


Intent i = new Intent();
i.setAction("com.symbol.datawedge.api.ACTION");
i.putExtra("com.symbol.datawedge.api.SET_DEFAULT_PROFILE", "<profile name>");

Parameters

ACTION [String]: "com.symbol.datawedge.api.ACTION"

EXTRA_DATA [String]: "com.symbol.datawedge.api.SET_DEFAULT_PROFILE"

<profile name>: The Profile name (a case-sensitive string) to set as the default Profile.

Result Codes

DataWedge returns the following error codes if the app includes the intent extras SEND_RESULT and COMMAND_IDENTIFIER to enable the app to get results using the DataWedge result intent mechanism. See Example, below.

  • PROFILE_ALREADY_SET - FAILURE
  • PROFILE_NOT_FOUND - FAILURE
  • PROFILE_HAS_APP_ASSOCIATION - FAILURE
  • PROFILE_NAME_EMPTY - FAILURE

Also see the Result Codes guide for more information.

Example Code


// define action and data strings
String setDefaultProfile = "com.symbol.datawedge.api.ACTION";
String extraData = "com.symbol.datawedge.api.SET_DEFAULT_PROFILE";

public void onResume() {
        // create the intent
        Intent i = new Intent();

        // set the action to perform
        i.setAction(setDefaultProfile);

        // add additional info (a name)
        i.putExtra(extraData, "myProfile");

        // send the intent to DataWedge
        this.sendBroadcast(i);
}

Generate and receive result codes

Command and configuration intent parameters determine whether to send result codes (disabled by default). When using SEND_RESULT, the COMMAND_IDENTIFIER is used to match the result code with the originating intent. Sample usage of these parameters is shown below.

Note: Modify this generic code to match the API being used.

// send the intent
    Intent i = new Intent();
    i.setAction(ACTION);
    i.putExtra("com.symbol.datawedge.api.CREATE_PROFILE", "Profile1");

// request and identify the result code
    i.putExtra("SEND_RESULT","true");
    i.putExtra("COMMAND_IDENTIFIER","123456789");
    this.sendBroadcast(i);

// register to receive the result
    public void onReceive(Context context, Intent intent){

        String command = intent.getStringExtra("COMMAND");
        String commandidentifier = intent.getStringExtra("COMMAND_IDENTIFIER");
        String result = intent.getStringExtra("RESULT");

        Bundle bundle = new Bundle();
        String resultInfo = "";
        if(intent.hasExtra("RESULT_INFO")){
            bundle = intent.getBundleExtra("RESULT_INFO");
            Set<String> keys = bundle.keySet();
            for (String key: keys) {
                resultInfo += key + ": "+bundle.getString(key) + "\n";
            }
        }

        String text = "Command: "+command+"\n" +
                      "Result: " +result+"\n" +
                      "Result Info: " +resultInfo + "\n" +
                      "CID:"+commandidentifier;

        Toast.makeText(context, text, Toast.LENGTH_LONG).show();

    };

SEE ALSO:

Zebra Support Central | Integrator Guides, Product Manuals, Software Downloads and Support

LaunchPad | Zebra Developer Community

Intent | Android Developers

Intents and Intent Filters | Android Developers

Android Intents | Tutorial