darryncampbell / darryncampbell-cordova-plugin-intent

General purpose intent shim layer for cordova appliations on Android. Handles various techniques for sending and receiving intents.
MIT License
86 stars 136 forks source link

How to pass byte array to Zebra PrintConnect #75

Closed jh6000 closed 4 years ago

jh6000 commented 5 years ago

I am trying to use the plugin to send intents to Zebra PrintConnect as per the Zebra PrintConnect user guide. This is the Java code sample I am trying to implement using the plugin:

HashMap<String, String> variableData = new HashMap<>();

 variableData.put("%PRODUCT_NAME%", "Apples");

 Intent intent = new Intent();

 intent.setComponent(new ComponentName "com.zebra.printconnect", "com.zebra.printconnect.print.TemplatePrintWithContentService"));

 intent.putExtra("com.zebra.printconnect.PrintService.TEMPLATE_DATA", templateBytes); // Template ZPL as UTF-8 encoded byte array
 intent.putExtra("com.zebra.printconnect.PrintService.VARIABLE_DATA", variableData);
 intent.putExtra("com.zebra.printconnect.PrintService.RESULT_RECEIVER", buildIPCSafeRec

I pass the TEMPLATE_DATA extra like this:

window['plugins'].intentShim.startService(
      {
        component: {
          package: 'com.zebra.printconnect',
          class: 'com.zebra.printconnect.print.TemplatePrintWithContentService'
        },
        extras: {
          'com.zebra.printconnect.PrintService.TEMPLATE_DATA': zplBytes,
          'com.zebra.printconnect.PrintService.VARIABLE_DATA': variableData
        }
      },

I've tried a number of approaches (putting in bundle, stringyfying) but I always I receive an error in logcat that the Zebra service expected byte[] but value was a [java.lang.string or bundle].

Does the plugin handle the passing of byte arrays and if so how would you recommend doing this?

darryncampbell commented 5 years ago

Hi, no, it doesn't seem like byte[] is supported - you may need to fork the repo and add this type around here: https://github.com/darryncampbell/darryncampbell-cordova-plugin-intent/blob/master/src/android/IntentShim.java#L565