Skip navigation
1 2 3 Previous Next

Label And Receipt Printing

32 Posts authored by: Robin West Expert
Robin West

Printing in Android

Posted by Robin West Expert May 28, 2013

Hi Everyone,

I thought, now that you know why printing is important and needs to be thought about earlier in the development process, you might want to know how to actually print with a Zebra device.  It’s a lot like making a connection to other devices.  The main difference is that most other devices, you are usually attempting to get information (like a picture, or a scan), and printers you are usually sending information. 


If you have any recommendations for content you want to see, please let me know.  For my example, I’m using a Motorola ET1, a Zebra QLn220 printer and the Zebra Link-OS Multiplatform SDK.  I’m going to create a connection, make sure the printer is ready, and then print something.  And now for some code…


import android.os.Looper;

import com.zebra.sdk.comm.BluetoothConnectionInsecure;

import com.zebra.sdk.comm.Connection;


public class BluetoothConnectionInsecureExample {

    public static void main(String[] args) {

        BluetoothConnectionInsecureExample example = new BluetoothConnectionInsecureExample();


        // The Bluetooth MAC address can be discovered, scanned, or typed in

        String theBtMacAddress = "00:11:BB:DD:55:FF";




    private void sendZplOverBluetooth(final String theBtMacAddress) {

        new Thread(new Runnable() {

            public void run() {

                try {

                    // Instantiate insecure connection for given Bluetooth MAC Address.

                    Connection thePrinterConn = new BluetoothConnectionInsecure(theBtMacAddress);



                    // Verify the printer is ready to print

                    if (isPrinterReady(thePrinterConn)) {



                    // Initialize



                    // Open the connection - physical connection is established here.



                    // This example prints "This is a ZPL test." near the top of the label.

                    String zplData = "^XA^FO20,20^A0N,25,25^FDThis is a ZPL test.^FS^XZ";


                    // Send the data to printer as a byte array.



                    // Make sure the data got to the printer before closing the connection



                    // Close the insecure connection to release resources.





            } catch (Exception e) {

                // Handle communications error here.







    private bool isPrinterReady(Connection thePrinterConn) {

        bool isOK = false;

        try {


            // Creates a ZebraPrinter object to use Zebra specific functionality like getCurrentStatus()

            ZebraPrinter printer = ZebraPrinterFactory.getInstance(connection);


            PrinterStatus printerStatus = printer.getCurrentStatus();

            if (printerStatus.isReadyToPrint) {

                isOK = true;

            } 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 media door 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) {



        return isOK;



Robin West

Welcome to the Zebra Blog!

Posted by Robin West Expert May 20, 2013

For this first post, I’m going back to basics.  Why is printing still needed? Why do you need to think about printing when creating apps? 


There are many use cases for printing depending on the type of application you are writing.  If you're creating applications for retail, you may need a way to createR110Xi4_shipping2_small.jpg shelf labels, or mark a price down on specific items.  You could also be tied in to a system to ship items or distribute tickets.  You could be engaging in mobile sales.  While many times e-mailing receipts works fine, many people prefer a printed receipt and some governments require it.


Printing in these environments is very different from printing at home or in the office.   In your office you may print reports, directions, or tickets.  The primary purpose for printing in business is to track items: provide visibility to what an item is, where it is, where has it been, and what’s its condition.  This is what Zebra calls the Visible Value Chain. Providing this visibility is vital for everything from shipped packages, to identifying people, to monetary transactions.  Solutions that do this are essential to attach the physical world to the digital.


Once you've determined the need to queue_busting_small (1).jpgadd tracking to your application, the printer becomes one device in the solution, similar to the barcode scanner, camera, or mobile computer.  Especially in the mobile world, the value of one device over another is how easy it is to work with and manage.  Managing other devices in mobility is very different than on a non-mobile OS.  There are no printer or peripheral device drivers for iOS or Android. 


This means developers have to have a better understanding of the devices they wish to communicate with.  Each peripheral device company has its own "language" that tells the device what to do with the data.  These languages are usually published and freely available.  For printers, the benefits to sending print language rather than printing with a driver are that the data sent is much smaller, the printer processes it much quicker, and the developer and user have access to a host of diagnostic information and settings allowing for optimized integration.  Zebra has made it as easy as possible for this integration with thorough documentation and the Zebra Link-OS Multiplatform SDK.


Please use the Zebra Launchpad forum to ask questions.  This forum is monitored by Zebra engineers from the Zebra ISV program.


Zebra Knowledge Base (Sample code, white papers, and helpful tips)

Zebra ISV Website

Zebra Link-OS Home Page

Zebra Programming Guide


  Robin West, architect at Zebra Technologies 

Filter Blog

By date:
By tag: