4 Replies Latest reply on Oct 17, 2017 12:44 AM by Nicola Lazzara Branched to a new discussion.

    Test printer status in Android

    Stephen Brennan

      I am developing an Android app which prints to a Zebra ZQ520 printer, over a Bluetooth connection, using the ZSDK API.  I would like to be able test if the connection to the printer is active or if I need to reconnect (eg when the printer has gone to sleep).  I have tried using the printer.getCurrentStatus() method, with the intention of then using the isReadyToPrint flag, but I am consistently getting a ZebraPrinterConnectionException ("Malformed status response - unable to determine printer status").  Is there any other way to check the printer/connection status?

        • Re: Test printer status in Android
          Manuel Caicedo-Rivera

          Hi Stephen,


          Please, follow the example below. It should work fine to check the status of the printer before to send a print job.

          Also, you can go to the link below to get more information about Zebra's API.

          Zebra API for Android (build v2.9.2275)


          package test.zebra.sdk.printer.examples;


          import com.zebra.sdk.comm.Connection;

          import com.zebra.sdk.comm.ConnectionException;

          import com.zebra.sdk.comm.BluetoothConnection;

          import com.zebra.sdk.printer.PrinterStatus;

          import com.zebra.sdk.printer.ZebraPrinter;

          import com.zebra.sdk.printer.ZebraPrinterFactory;

          import com.zebra.sdk.printer.ZebraPrinterLanguageUnknownException;


          public class PrinterStatusExample {


               public static void main(String[] args) throws Exception {

              Connection connection = new BluetoothConnection(theBTMacAddress);

                   try {


                       ZebraPrinter printer = ZebraPrinterFactory.getInstance(connection);


                       PrinterStatus printerStatus = printer.getCurrentStatus();

                       if (printerStatus.isReadyToPrint) {

                           System.out.println("Ready To Print");

                       } else if (printerStatus.isPaused) {

                           System.out.println("Cannot Print because the printer is paused.");

                       } else if (printerStatus.isHeadOpen) {

                           System.out.println("Cannot Print because the printer head is open.");

                       } else if (printerStatus.isPaperOut) {

                           System.out.println("Cannot Print because the paper is out.");

                       } else {

                           System.out.println("Cannot Print.");


                   } catch (ConnectionException e) {


                   } catch (ZebraPrinterLanguageUnknownException e) {


                   } finally {





          2 of 2 people found this helpful
            • Re: Test printer status in Android
              Manuel Caicedo-Rivera

              Another situation that could be happening is related to the Printer language:

              The ZQ510 printer normally is by default in Line_Print.


              For more information about it, I would recommend to review this article.

              Zebra Technologies - Best Practices in Creating a Printing Application for Zebra Printers


              We recommend to set up the language to ZPL.

              Please, try this line before to get status

              SGD.SET("device.languages", "hybrid_xml_zpl", connection);


              SGD.SET("device.languages", "zpl", connection);


              Please, let me know if you need more assistance.




              1 of 1 people found this helpful
                • Re: Test printer status in Android
                  Nicola Lazzara

                  I think that there is the same problem on Xamarin.Form solution for Ios, when i try to print, at first time, the method :


                          private bool SetPrintLanguage(IConnection connection)


                              string setLanguage = "! U1 setvar \"device.languages\" \"zpl\"\r\n\r\n! U1 getvar \"device.languages\"\r\n\r\n";

                              byte[] response = connection.SendAndWaitForResponse(Encoding.UTF8.GetBytes(setLanguage), 1000, 1000);

                              string s = Encoding.UTF8.GetString(response, 0, response.Length);

                              if (!s.Contains("zpl"))


                                  string error = "Not a ZPL printer.";

                                  return false;


                              return true;



                  go in exception almost always, maybe i can fix this in Xamarin.Forms using te line of code that you have suggest [SGD.SET("device.languages", "zpl", connection);] on the post above? How i can use it? My solution is a Xamarin Cross Platform Solution (and i using VisualStudio 2017) and i use Link_OS_Xamarin_Sdk 1.1.75?


                  Thanks in advance


              • Re: Test printer status in Android
                Stephen Brennan

                Thanks Manuel.  I downloaded the latest version of the SDK and actually found the answer in the included demo app.  For the ZQ520, I needed to get the status using ZebraPrinterLinkOs.


                Full code:


                ZebraPrinterLinkOs linkOsPrinter = ZebraPrinterFactory.createLinkOsPrinter(printer);


                PrinterStatus printerStatus = (linkOsPrinter != null) ? linkOsPrinter.getCurrentStatus() : printer.getCurrentStatus();