Search code examples
androidimagebluetoothzebra-printers

Printing to Zebra QLn320 from Android


I am currently trying to print an image saved on my android device on a bt enabled zebra printer and I've followed the examples from the documentation, but I can't for the life of me figure out why it's not printing. The BT icon flashes on the printer for a while so I know the connection is being made, but nothing happens. When i call the printImage() function I am giving it the location of the image and the desired width and height. I know the file exists because I can see it displayed in an imageview. Here is my code:

private void printImageTest() {

    new Thread(new Runnable() {
        @Override
        public void run() {

            try {
                Looper.prepare();
                Connection connection = new BluetoothConnection("AC:3F:A4:13:C2:24");
                connection.open();
                ZebraPrinter printer = ZebraPrinterFactory.getInstance(connection);
                printer.printImage(signatureFile, 100, 100);
                Thread.sleep(2000);
                connection.close();
                Looper.myLooper().quit();
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (ZebraPrinterLanguageUnknownException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }).start();
}

Solution

  • Please find the link to ZPL language zpl programming guide in section Image Load

    Connect to printer:

    BluetoothConnection printerConnection = new BluetoothConnection(printerAddress);
        printerConnection.open();
    
        if (!printerConnection.isConnected()) {
            throw new Exception("Could not open bluetooth connection");
        }
    
        //print
        ZebraPrinter printer = ZebraPrinterFactory.getInstance(printerConnection);
        PrinterLanguage pl = printer.getPrinterControlLanguage();
        if (pl == PrinterLanguage.CPCL) {
    
        } else {
            //byte[] configLabel = createZplReceipt().getBytes();
            byte[] configLabel = zplContent.getBytes();
            printerConnection.write(configLabel);
        }
    
        printerConnection.close();
    

    Then send a ZPL string to printer:

    enter image description here