Service app DataWedges API

Hi, i am using a Zebra TC26 scanner and want to create a background java service that can trigger scans and read barcodes.

I have a app that has no activity and only one service (this service is a middleman between my app and the zebra scanner api). I implemented a BroadcastReceiver that seems to be working for action results such as the soft scan trigger result and the config result. Send a SOFT_SCAN_TRIGGER action will start scanning but i never receive a result with the barcode. Only the command results.

When i run the same code in a seperate app with an activity it works and i reveive the scanned code. What do i need to do so i can receive the scanned code with this service that has no activity?

Here is my code so far:

public class MyService extends Service {

private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String decodedSource = intent.getStringExtra(SOURCE);
String decodedData = intent.getStringExtra(DATA_STRING);
// ...
}
};

// ...

private void startListening() {
IntentFilter filter = new IntentFilter();
filter.addCategory(Intent.CATEGORY_DEFAULT);
filter.addAction(MY_ACTION);
registerReceiver(broadcastReceiver, filter);
}

public void triggerScan() {
Intent i = new Intent();
i.setAction(ACTION);
i.putExtra(SWITCH_PROFILE, MY_PROFILE);
i.putExtra("SEND_RESULT","true");
i.putExtra(SOFT_SCAN_TRIGGER, "START_SCANNING");
this.sendBroadcast(i);
}

// ...

private void initConfiguration(){
Bundle bundleMain = new Bundle();
// profile name and state
bundleMain.putString("PROFILE_NAME", MY_PROFILE);
bundleMain.putString("PROFILE_ENABLED","true");
bundleMain.putString("CONFIG_MODE", "UPDATE");

// Associate profile with this app
Bundle appConfig = new Bundle();
appConfig.putString("PACKAGE_NAME", getPackageName());
appConfig.putStringArray("ACTIVITY_LIST", new String[]{"*"});
bundleMain.putParcelableArray("APP_LIST", new Bundle[]{appConfig});

// Configure intent output for captured data to be sent to this app
Bundle bundleIntentOutConfig = new Bundle();
bundleIntentOutConfig.putString("PLUGIN_NAME", "INTENT");
bundleIntentOutConfig.putString("RESET_CONFIG", "false");

// Param list properties
Bundle bundleIntentParams = new Bundle();
bundleIntentParams.putString("intent_output_enabled", "true");
bundleIntentParams.putString("intent_action", MY_ACTION);
bundleIntentParams.putString("intent_category", Intent.CATEGORY_DEFAULT);
bundleIntentParams.putString("intent_delivery", "2"); //0 - activity, 1 - service, 2 - Broadcast
bundleIntentOutConfig.putBundle("PARAM_LIST", bundleIntentParams);

ArrayList<Bundle> bundlePluginConfig = new ArrayList<>();
bundlePluginConfig.add(bundleIntentOutConfig);

bundleMain.putParcelableArrayList("PLUGIN_CONFIG", bundlePluginConfig);

Intent bundleSetConfig = new Intent();
bundleSetConfig.setAction(ACTION);
bundleSetConfig.putExtra(SET_CONFIG, bundleMain);
bundleSetConfig.putExtra("SEND_RESULT", "COMPLETE_RESULT"); //Supported values: NONE, LAST_RESULT, COMPLETE_RESULT
bundleSetConfig.putExtra("COMMAND_IDENTIFIER", "INTENT_API");
}
}

Darryn Campbell
Hi, you want to configure

Hi, you want to configure DataWedge to send a startService(), then you can listen for scans using your Android Service.  The sample app can do this to show the principle, https://github.com/ZebraDevs/DataWedge-Android-Samples/blob/master/DataW... and https://github.com/ZebraDevs/DataWedge-Android-Samples/blob/master/DataW...

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments