Test printer status in Android

// Expert user has replied.
S Stephen Brennan 2 years 11 months ago
332 3 0

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?

Please register or login to post a reply

3 Replies

S 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();

M 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 {
             connection.open();
             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) {
             e.printStackTrace();
         } catch (ZebraPrinterLanguageUnknownException e) {
             e.printStackTrace();
         } finally {
             connection.close();
         }
     }
}

M 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);
or
SGD.SET("device.languages", "zpl", connection);

Please, let me know if you need more assistance.

Thanks,
MC

CONTACT
Can’t find what you’re looking for?