Skip to content
This repository has been archived by the owner on Mar 1, 2022. It is now read-only.

Commit

Permalink
Updated to cover the new DataWedge 6.2 APIs available on Zebra device…
Browse files Browse the repository at this point in the history
…s that run DataWedge 6.2 and higher.
  • Loading branch information
darryncampbell committed Apr 20, 2017
1 parent 68d858a commit ac32c8d
Show file tree
Hide file tree
Showing 5 changed files with 361 additions and 92 deletions.
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
# DataWedge-API-Exerciser

This application has been written to exercise the Zebra DataWedge Data Capture API (http://techdocs.zebra.com/datawedge/5-0/guide/api/).
*This application is provided without guarantee or warranty*
=========================================================

###This application is provided without guarantee or warranty
This application has been written to exercise the Zebra DataWedge Data Capture API (http://techdocs.zebra.com/datawedge/6-2/guide/api/).

Zebra DataWedge is a 'zero code' solution to capture barcode, magnetic stripe and OCR data on Zebra devices. DataWedge is a profile-based service running on Zebra mobile computers and offers an intent based API for user applications to interact and control. The intent based API offers limited functionality for controlling the scanning and profile aspects of DataWedge

Application to exercise the DataWedge Intent API for testing purposes
##APIs:
## APIs (6.x):
* SoftScanTrigger - used to start, stop or toggle a software scanning trigger
* ScannerInputPlugin - enable/disable the scanner Plug-in used by the active Profile
* enumerateScanners - returns a list of scanners available on the device
* setDefaultProfile - sets the specified Profile as the default Profile
* resetDefaultProfile - resets the default Profile to Profile0
* switchToProfile - switches to the specified Profile

##Device Configuration:
## APIs (6.2):
* Delete Profile
* Clone Profile
* Rename Profile
* Get Active Profile
* List Profiles
* Enable / Disable Datawedge

## Device Configuration:
1. Set up a Datawedge profile that will be in effect when this application is run [to get started easily, just modify 'Profile0 (default)].
2. Ensure Datawedge is enabled and the configured profile has enabled the 'Barcode input' plugin.
* To test steps 1 & 2 launch any app and press the barcode trigger, you should see a beam.
Expand All @@ -24,7 +33,7 @@ Application to exercise the DataWedge Intent API for testing purposes
* Intent action: com.zebra.dwapiexerciser.ACTION
* Intent category: leave blank

##Use:
## Use:
Hopefully the UI is self explanatory. Returned barcode data is shown at the top of the view with some indication whether the intent (from Datawedge) was invoked through startActivity(), sendBroadcast() or startService().

To mimic DataWedge on a non-Zebra device you can use adb to send an intent of the same format that DataWedge would usually send on scan:
Expand Down
202 changes: 128 additions & 74 deletions app/src/main/java/com/zebra/datawedgeexerciser/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
Expand All @@ -18,30 +20,34 @@

public class MainActivity extends AppCompatActivity {

// 6.x API
private static final String ACTION_SOFTSCANTRIGGER = "com.symbol.datawedge.api.ACTION_SOFTSCANTRIGGER";
private static final String ACTION_SCANNERINPUTPLUGIN = "com.symbol.datawedge.api.ACTION_SCANNERINPUTPLUGIN";
private static final String ACTION_ENUMERATESCANNERS = "com.symbol.datawedge.api.ACTION_ENUMERATESCANNERS";
private static final String ACTION_SETDEFAULTPROFILE = "com.symbol.datawedge.api.ACTION_SETDEFAULTPROFILE";
private static final String ACTION_RESETDEFAULTPROFILE = "com.symbol.datawedge.api.ACTION_RESETDEFAULTPROFILE";
private static final String ACTION_SWITCHTOPROFILE = "com.symbol.datawedge.api.ACTION_SWITCHTOPROFILE";

// Parameters associated with the application actions
// Intent Extras (DataWedge 6.x)
private static final String EXTRA_PARAMETER = "com.symbol.datawedge.api.EXTRA_PARAMETER";
private static final String EXTRA_PROFILENAME = "com.symbol.datawedge.api.EXTRA_PROFILENAME";
private static final String EXTRA_GET_ACTIVE_PROFILE = "com.symbol.datawedge.api.GET_ACTIVE_PROFILE";
private static final String EXTRA_GET_PROFILES_LIST = "com.symbol.datawedge.api.GET_PROFILES_LIST";
private static final String EXTRA_EMPTY = "";

// Enumerated Scanner receiver
private static final String ACTION_ENUMERATEDLISET = "com.symbol.datawedge.api.ACTION_ENUMERATEDSCANNERLIST";
private static final String ACTION_ENUMERATEDLIST = "com.symbol.datawedge.api.ACTION_ENUMERATEDSCANNERLIST";
private static final String KEY_ENUMERATEDSCANNERLIST = "DWAPI_KEY_ENUMERATEDSCANNERLIST";

// DataWedge 6.2 API
private static final String ACTION_DATAWEDGE_FROM_6_2 = "com.symbol.datawedge.api.ACTION";

private static final String ACTION_RESULT_DATAWEDGE_FROM_6_2 = "com.symbol.datawedge.api.RESULT_ACTION";
// Intent Extras (DataWedge 6.2)
private static final String EXTRA_GET_ACTIVE_PROFILE = "com.symbol.datawedge.api.GET_ACTIVE_PROFILE";
private static final String EXTRA_GET_PROFILES_LIST = "com.symbol.datawedge.api.GET_PROFILES_LIST";
private static final String EXTRA_EMPTY = "";
private static final String EXTRA_DELETE_PROFILE = "com.symbol.datawedge.api.DELETE_PROFILE";
private static final String EXTRA_CLONE_PROFILE = "com.symbol.datawedge.api.CLONE_PROFILE";
private static final String EXTRA_RENAME_PROFILE = "com.symbol.datawedge.api.RENAME_PROFILE";
private static final String EXTRA_ENABLE_DATAWEDGE = "com.symbol.datawedge.api.ENABLE_DATAWEDGE";
// Extra Parameter results (from 6.2 onwards)
private static final String EXTRA_RESULT_GET_ACTIVE_PROFILE = "com.symbol.datawedge.api.RESULT_GET_ACTIVE_PROFILE";
private static final String EXTRA_RESULT_GET_PROFILE_LIST = "com.symbol.datawedge.api.RESULT_ACTIVE_PROFILE";
private static final String EXTRA_RESULT_GET_PROFILE_LIST = "com.symbol.datawedge.api.RESULT_GET_PROFILES_LIST";

private static final String LOG_TAG = "Datawedge API Exerciser";

Expand All @@ -54,6 +60,30 @@ protected void onCreate(Bundle savedInstanceState) {
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setDisplayShowTitleEnabled(true);

// UI stuff
final Spinner spinnerProfileCommands = (Spinner) findViewById(R.id.spinnerSelectCommand62);
final TextView txtProfileCommandParameter = (TextView) findViewById(R.id.txtProfileCommandParameter);
final EditText editProfileCommandParameter = (EditText) findViewById(R.id.editProfileCommandParameter);
spinnerProfileCommands.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
if (position == 0 || position == 1)
{
txtProfileCommandParameter.setEnabled(false);
editProfileCommandParameter.setEnabled(false);
}
else
{
txtProfileCommandParameter.setEnabled(true);
editProfileCommandParameter.setEnabled(true);
}
}
@Override
public void onNothingSelected(AdapterView<?> parentView) {
// your code here
}
});

// Were we invoked through a StartActivity intent?
Intent initiatingIntent = getIntent();
if (initiatingIntent != null)
Expand All @@ -64,21 +94,19 @@ protected void onCreate(Bundle savedInstanceState) {
// Received a barcode through StartActivity
displayScanResult(initiatingIntent, "via StartActivity");
}

}

// SoftScanTrigger Intent
// SoftScanTrigger Intent (6.x API)
final Spinner spinnerSoftScanTrigger = (Spinner) findViewById(R.id.spinnerSoftScanTrigger);
final Button btnSoftScanTrigger = (Button) findViewById(R.id.btnSoftScanTrigger);
btnSoftScanTrigger.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Send SoftScanTriggerIntent
sendDataWedgeIntentWithExtra(ACTION_SOFTSCANTRIGGER, EXTRA_PARAMETER, spinnerSoftScanTrigger.getSelectedItem().toString());

}
});

// ScannerInputPlugin
// ScannerInputPlugin (6.x API)
final CheckBox checkScannerInputPlugin = (CheckBox) findViewById(R.id.checkScannerInputPlugin);
final Button btnScannerInputPlugin = (Button) findViewById(R.id.btnScannerInputPlugin);
btnScannerInputPlugin.setOnClickListener(new View.OnClickListener() {
Expand All @@ -91,24 +119,15 @@ public void onClick(View v) {
}
});

// EnumerateScanners
// EnumerateScanners (6.x API)
final Button btnEnumerateScanners = (Button) findViewById(R.id.btnEnumerateScaners);
btnEnumerateScanners.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
sendDataWedgeIntentWithoutExtra(ACTION_ENUMERATESCANNERS);
}
});
// Create a filter for the broadcast intent
IntentFilter filter = new IntentFilter();
filter.addAction(ACTION_ENUMERATEDLISET);
// Whilst we're here also register to receive broadcasts via DataWedge scanning
filter.addAction(getResources().getString(R.string.activity_intent_filter_action));
filter.addAction(getResources().getString(R.string.activity_action_from_service));
filter.addAction(EXTRA_RESULT_GET_ACTIVE_PROFILE);
filter.addAction(EXTRA_RESULT_GET_PROFILE_LIST);
registerReceiver(myBroadcastReceiver, filter);

// SetDefaultProfile
// SetDefaultProfile (6.x API)
final EditText editSetDefaultProfile = (EditText) findViewById(R.id.editSetDefaultProfile);
final Button btnSetDefaultProfile = (Button) findViewById(R.id.btnSetDefaultProfile);
btnSetDefaultProfile.setOnClickListener(new View.OnClickListener() {
Expand All @@ -119,15 +138,15 @@ public void onClick(View v) {
}
});

// ResetDefaultProfile
// ResetDefaultProfile (6.x API)
final Button btnResetDefaultProfile = (Button) findViewById(R.id.btnResetDefaultProfile);
btnResetDefaultProfile.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
sendDataWedgeIntentWithoutExtra(ACTION_RESETDEFAULTPROFILE);
}
});

// SwitchToProfile
// SwitchToProfile (6.x API)
final EditText editSwitchToProfile = (EditText) findViewById(R.id.editSwitchToProfile);
final Button btnSwitchToProfile = (Button) findViewById(R.id.btnSwitchToProfile);
btnSwitchToProfile.setOnClickListener(new View.OnClickListener() {
Expand All @@ -136,42 +155,59 @@ public void onClick(View v) {
}
});

// GetActiveProfile
final Button btnGetActiveProfile = (Button) findViewById(R.id.btnGetActiveProfile);
btnGetActiveProfile.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view) {
sendDataWedgeIntentWithExtra(ACTION_DATAWEDGE_FROM_6_2, EXTRA_GET_ACTIVE_PROFILE, EXTRA_EMPTY);
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
for (String key : bundle.keySet()) {
Object value = bundle.get(key);
Log.d(LOG_TAG, String.format("%s %s (%s)", key,
value.toString(), value.getClass().getName()));
}
// Profile based commands newly added for 6.2 (Delete, Clone, Rename) (6.2 API)
final Button btnProfileCommand62 = (Button) findViewById(R.id.btnProfileCommand62);
btnProfileCommand62.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String commandToExecute = spinnerProfileCommands.getSelectedItem().toString();
Spinner profileListSpinner = (Spinner) findViewById(R.id.spinnerSelectProfile62);
String selectedProfile = profileListSpinner.getSelectedItem().toString();
final EditText editProfileCommandParameter = (EditText) findViewById(R.id.editProfileCommandParameter);
String newProfile = editProfileCommandParameter.getText().toString();
if (commandToExecute.equals(getString(R.string.command_refresh_ui)))
{
sendDataWedgeIntentWithExtra(ACTION_DATAWEDGE_FROM_6_2, EXTRA_GET_PROFILES_LIST, EXTRA_EMPTY);
sendDataWedgeIntentWithExtra(ACTION_DATAWEDGE_FROM_6_2, EXTRA_GET_ACTIVE_PROFILE, EXTRA_EMPTY);
}
else if (commandToExecute.equals(getString(R.string.command_delete_profile)))
{
String[] values = {selectedProfile};
sendDataWedgeIntentWithExtra(ACTION_DATAWEDGE_FROM_6_2, EXTRA_DELETE_PROFILE, values);
}
else if (commandToExecute.equals(getString(R.string.command_clone_profile)))
{
String[] values = {selectedProfile, newProfile};
sendDataWedgeIntentWithExtra(ACTION_DATAWEDGE_FROM_6_2, EXTRA_CLONE_PROFILE, values);
}
else if (commandToExecute.equals(getString(R.string.command_rename_profile)))
{
String[] values = {selectedProfile, newProfile};
sendDataWedgeIntentWithExtra(ACTION_DATAWEDGE_FROM_6_2, EXTRA_RENAME_PROFILE, values);
}
sendDataWedgeIntentWithExtra(ACTION_DATAWEDGE_FROM_6_2, EXTRA_GET_PROFILES_LIST, EXTRA_EMPTY);
sendDataWedgeIntentWithExtra(ACTION_DATAWEDGE_FROM_6_2, EXTRA_GET_ACTIVE_PROFILE, EXTRA_EMPTY);
}
});

// GetProfilesList
final Button btnGetProfilesList = (Button) findViewById(R.id.btnGetProfilesList);
btnGetProfilesList.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view) {
sendDataWedgeIntentWithExtra(ACTION_DATAWEDGE_FROM_6_2, EXTRA_GET_PROFILES_LIST, EXTRA_EMPTY);
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
for (String key : bundle.keySet()) {
Object value = bundle.get(key);
Log.d(LOG_TAG, String.format("%s %s (%s)", key,
value.toString(), value.getClass().getName()));
}
}
// DisableEnableDatawedge (6.2 API)
final CheckBox checkDisableEnableDatawedge = (CheckBox) findViewById(R.id.checkDisableEnableDataWedge);
final Button btnDisableEnableDatawedge = (Button) findViewById(R.id.btnDisableEnableDataWedge);
btnDisableEnableDatawedge.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
sendDataWedgeIntentWithExtra(ACTION_DATAWEDGE_FROM_6_2, EXTRA_ENABLE_DATAWEDGE, checkDisableEnableDatawedge.isChecked());
}
});

// Create a filter for the broadcast intent
IntentFilter filter = new IntentFilter();
filter.addAction(ACTION_ENUMERATEDLIST); // DW 6.x
filter.addAction(ACTION_RESULT_DATAWEDGE_FROM_6_2);// DW 6.2
filter.addCategory(Intent.CATEGORY_DEFAULT); // NOTE: this IS REQUIRED for DW6.2!
// Whilst we're here also register to receive broadcasts via DataWedge scanning
filter.addAction(getResources().getString(R.string.activity_intent_filter_action));
filter.addAction(getResources().getString(R.string.activity_action_from_service));
registerReceiver(myBroadcastReceiver, filter);

}

@Override
Expand All @@ -181,15 +217,22 @@ protected void onDestroy()
unregisterReceiver(myBroadcastReceiver);
}

@Override
protected void onResume()
{
super.onResume();
sendDataWedgeIntentWithExtra(ACTION_DATAWEDGE_FROM_6_2, EXTRA_GET_PROFILES_LIST, EXTRA_EMPTY);
sendDataWedgeIntentWithExtra(ACTION_DATAWEDGE_FROM_6_2, EXTRA_GET_ACTIVE_PROFILE, EXTRA_EMPTY);
}

private BroadcastReceiver myBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(ACTION_ENUMERATEDLISET)) {
if (action.equals(ACTION_ENUMERATEDLIST)) {
Bundle b = intent.getExtras();
for (String key : b.keySet())
{
// Note, documentation for key was wrong for this. I will get that fixed
Log.v(LOG_TAG, key);
}
String[] scanner_list = b.getStringArray(KEY_ENUMERATEDSCANNERLIST);
Expand Down Expand Up @@ -220,27 +263,22 @@ else if (action.equals(getResources().getString(R.string.activity_action_from_se
// Catch if the UI does not exist when we receive the broadcast... this is not designed to be a production app
}
}
// TODO: HOW ARE THE 6.2 RETURN VALUES RECEIVED?
else if (action.equals(EXTRA_RESULT_GET_ACTIVE_PROFILE) || action.equals(EXTRA_RESULT_GET_PROFILE_LIST))
else if (action.equals(ACTION_RESULT_DATAWEDGE_FROM_6_2))
{
Bundle bundle = intent.getExtras();
if (bundle != null) {
for (String key : bundle.keySet()) {
Object value = bundle.get(key);
Log.d(LOG_TAG, String.format("%s %s (%s)", key,
value.toString(), value.getClass().getName()));
}
}
if (intent.hasExtra(EXTRA_GET_ACTIVE_PROFILE))
if (intent.hasExtra(EXTRA_RESULT_GET_ACTIVE_PROFILE))
{
Toast.makeText(getApplicationContext(), intent.getStringExtra(EXTRA_GET_ACTIVE_PROFILE), Toast.LENGTH_LONG).show();
String activeProfile = intent.getStringExtra(EXTRA_RESULT_GET_ACTIVE_PROFILE);
TextView txtActiveProfile = (TextView) findViewById(R.id.txtActiveProfileOutput62);
txtActiveProfile.setText(activeProfile);
}
else if (intent.hasExtra(EXTRA_GET_PROFILES_LIST))
else if (intent.hasExtra(EXTRA_RESULT_GET_PROFILE_LIST))
{
String[] profilesList = intent.getStringArrayExtra(EXTRA_GET_PROFILES_LIST);
int i = 0;

i++;
String[] profilesList = intent.getStringArrayExtra(EXTRA_RESULT_GET_PROFILE_LIST);
Spinner profileListSpinner = (Spinner) findViewById(R.id.spinnerSelectProfile62);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getBaseContext(),
android.R.layout.simple_spinner_item, profilesList);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
profileListSpinner.setAdapter(adapter);
}
}
}
Expand All @@ -254,6 +292,22 @@ private void sendDataWedgeIntentWithExtra(String action, String extraKey, String
this.sendBroadcast(dwIntent);
}

private void sendDataWedgeIntentWithExtra(String action, String extraKey, String[] extraValues)
{
Intent dwIntent = new Intent();
dwIntent.setAction(action);
dwIntent.putExtra(extraKey, extraValues);
this.sendBroadcast(dwIntent);
}

private void sendDataWedgeIntentWithExtra(String action, String extraKey, boolean extraValue)
{
Intent dwIntent = new Intent();
dwIntent.setAction(action);
dwIntent.putExtra(extraKey, extraValue);
this.sendBroadcast(dwIntent);
}

private void sendDataWedgeIntentWithoutExtra(String action)
{
Intent dwIntent = new Intent();
Expand Down
Loading

0 comments on commit ac32c8d

Please sign in to comment.