8 Replies Latest reply on Jul 31, 2018 1:55 PM by Jeff Gonzalez

    PrintConnect via Chrome Android Intents with javascript/html?

    Brian TT

      Is it possible to use PrintConnect with Android Intents from Chrome/javascript/html?

      AFAIK the Zebra Browser only works on select Android devices;  TestConnect didn't install on my Samsung T800 either.


      If so, I'm looking for some samples as I've only seen Java versions.


      My non-working attempts (I'm unsure of the uri/scheme/package and how to pass VARIABLE_DATA, and whether RESULT_RECEIVER is required):


      window.location.href = "intent://printconnect/#TemplatePrintService;scheme=printconnect;package=com.zebra.printconnect;S.TEMPLATE_FILE_NAME=HelloWorld.zpl;end";


      window.location.href = "intent://com.zebra.printconnect.print.TemplatePrintService/#TemplatePrintService;scheme=com.zebra.printconnect;package=com.zebra.printconnect;S.TEMPLATE_FILE_NAME=HelloWorld.zpl;end";



      window.location.href = "intent://com.zebra.printconnect.print.TemplatePrintService/#TemplatePrintService;scheme=com.zebra.printconnect;package=com.zebra.printconnect;S.TEMPLATE_FILE_NAME=HelloWorld.zpl;S.RESULT_RECEIVER='';end";

      // S.RESULT_RECEIVER= ??? null


      window.location.href = "intent://com.zebra.printconnect/#TemplatePrintService;scheme=printconnect;package=com.zebra.printconnect;S.TEMPLATE_FILE_NAME=myTicket.prn;S.VARIABLE_DATA=%ticketNumber%=1234567;end";

        • Re: PrintConnect via Chrome Android Intents with javascript/html?
          Robin West

          Hi Brian, I'm afraid PrintConnect was not designed with this use case in mind.  If you want to do something like this, I recommend looking into one of our partners like MobiPrint by Arrowhead.

            • Re: PrintConnect via Chrome Android Intents with javascript/html?
              Brian TT

              Is the limitation due to the formatting of intents from an Android App vs formatting from Android Chrome Browser?


              If so, would an intermediary proxy app based on sample code from the user guide work, sending PrintConnect correctly formatted data ? (page 90 of  https://www.zebra.com/content/dam/zebra_new_ia/en-us/solutions-verticals/product/Software/Printer%20Software/Link-OS/pri… )

              • Re: PrintConnect via Chrome Android Intents with javascript/html?
                Jeff Gonzalez

                I created a sample Android app using Xamarin and was able to successfully send a print intent.  However, I'd like to do this from Chrome on my TC56.  Supposedly this is possible:


                Android Intents with Chrome - Google Chrome


                So why wouldn't I be able to send an intent from Chrome if I can do it from my own Android app?  Does anyone have experience with this?

                  • Re: PrintConnect via Chrome Android Intents with javascript/html?
                    Brian TT

                    As mentioned on that linked page, Chrome requires a user-gesture to launch the intent (a button/link on a viewed webpage), where Firefox could do it with javascript location.href=...


                    Another question was how to format variables in the href, as the Java example did with a hashmap:

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

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

                    variableData.put("%MSRP%", "$123.00");

                    variableData.put("%PCT%", "50");

                    variableData.put("%FINAL%", "$0.50");

                    variableData.put("%UPC_CODE%", "12345678");

                    intent.putExtra("com.zebra.printconnect.PrintService.VARIABLE_DATA", variableData);


                    .. and whether RESULT_RECEIVER is required

                      • Re: PrintConnect via Chrome Android Intents with javascript/html?
                        Jeff Gonzalez

                        My understanding is the requirement for a user gesture is for security purposes.  I'm okay with pushing a button/link to print.  I just need a way to print from Chrome as I am required to use Chrome.  I don't think the hashmap is a requirement; there is an intent that lets you write out "raw" output however you wish as long as it is valid ZPL.


                        The result receiver is an interesting thing.  I created a sample Android app and confirmed it was working with my own receiver.  The receiver seems to just be a way to get info on the print results.  I'm not sure if it would be required as mine doesn't do anything.  I'm sure you could pass in the default or maybe null.  I'd like to look more into how Chrome handles Intents.  It's just another Android app, right?  It should handle Intents just like any other.  The concern is how it exposes this to the web developer.


                        Would you mind sharing the HTML/JavaScript you are using to get things working on FireFox?  What code should I use to format the Intent to work from a button or link?  Thanks.

                          • Re: PrintConnect via Chrome Android Intents with javascript/html?
                            Brian TT

                            // worked on Firefox, not Chrome:

                            window.location.href = "intent://printproxy/#Intent;scheme=printproxy;package=org.thatsme.printproxy;S.ticketList=" + ticketList.join() + ";S.date=" + new Date().toISOString() + ";S.user=" + username + ";end";




                            // Chrome link

                            <a href="intent://printproxy/#Intent;scheme=printproxy;package=org.thatsme.printproxy;S.action=share;S.type=url;end">PrintProxy</a>






                            // AndroidManifest.xml





                            <!--<action android:name="pprs" />-->

                            <!--<action android:name="org.thatsme.printproxy" />-->

                            <!--<action android:name="android.intent.action.SEND"/>-->

                            <action android:name="android.intent.action.VIEW"/>

                            <!--<action android:name="android.intent.action.SCAN"/>-->

                            <category android:name="android.intent.category.DEFAULT"/>

                            <category android:name="android.intent.category.BROWSABLE" />

                            <!--<data android:mimeType="text/plain"/>-->



                            <!--<data android:scheme="printproxy" />-->

                            <data android:scheme="printproxy" android:host="printproxy" android:path="/"/>








                            Intent intent = getIntent();

                            Uri data = intent.getData();

                            Log.v("debug", "actionIs: " + intent.getAction() + ", typeIs: " + intent.getType() + ", getExtras: " + intent.getExtras());

                            Bundle bundle = intent.getExtras();

                            if (bundle!=null) {

                              String ticketList = intent.getStringExtra("ticketList");

                              String date = intent.getStringExtra("date");

                              String user = intent.getStringExtra("user");




                            and I used, defining the zpl in the java code

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

                              • Re: PrintConnect via Chrome Android Intents with javascript/html?
                                Jeff Gonzalez

                                Is your "print proxy" and Android app that passes the intent along to PrintConnect?


                                Here is what I've tried so far:


                                <a href="intent://#Intent;package=com.zebra.printconnect;component=com.zebra.printconnect.print.TemplatePrintService;S.TEMPLATE_FILE_NAME=HelloWorld.zpl;end"> Print something! </a>


                                When I click this in Chrome on my TC56, it opens the PrintConnect page in the Google Play Store.


                                I think the problem is that the following doesn't appear to be set in PrintConnect's Android.manifest, which is required for Google Chrome:




                                You seem to have this set in your proxy, however, so I'm not sure why your solution didn't work in Chrome using your proxy.  Perhaps Android detects the original intent request started in Chrome and won't allow it to finish in PrintConnect when it is not marked as BROWSABLE?