54
Printing with Android Devices Cathy Zhang and James Chong CDC Firmware Engineer, CDC Firmware manager

Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

  • Upload
    others

  • View
    22

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Printing with Android Devices

Cathy Zhang and James Chong

CDC Firmware Engineer, CDC Firmware manager

Page 2: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Workshop’s Goals

1. Introduce you to commonly used Zebra Printer terminology. 简要介绍最常用的斑马打印机术语

2. Familiarize with Zebra’s Printing Best Practices 熟悉斑马打印的最佳范例

3. Learn basic printing concepts with Zebra devices 了解基本的斑马打印概念

4. Learn how to use the LINK-OS SDK and Zebra’s tools to develop powerful printing apps. 了解怎样使用LINK-OS SDK和斑马工具去开发一个打印的应用程序

5. Build a functional use case with Android Studio, Zebra Mobile Computer(MC40) and Zebra Mobile Printer(QLN320) 用Android studio, 手持终端(MC40), 和移动打印机(QLN320)构建一个用例

Page 3: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Agenda

• Introduction

简要介绍

• Concepts of Printing with Zebra Devices

斑马打印设备概念

• LINK-OS Android API Overview

LINK-OS 安卓API概述

• Build an app

创建一个应用程序

Page 4: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Printing with Android Devices Introduction

Page 5: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Zebra Terminology • ZPL – Zebra Programming Language, one type of programming language utilized by Zebra printers. This is the

recommended development language. Other languages are EPL, CPCL and Line Print.

• ZPL Command: An instruction sent to the printer to configure the printer, print label (formats/templates),and get device status information (ex. ^B8 command prints a EAN-8 bar code).

• ZPL Format : One time send (all of the data is sent together) of a static form built with ZPL code to be printed or downloaded into the printer.

• ZPL Template: A dynamic form built with ZPL code to be downloaded into the printer that adds variable data fields.

• Recall ZPL Template: Prints by dynamically allocating values to variables in a ZPL template previously downloaded to the printer.

• ZPL RFID Command: In addition to reading or encoding RFID tags, the RFID ZPL commands also provide for RFID exception handling, such as setting the number of read/write retries before declaring a transponder defective (set with ^RR, ^RT, and ^WT) or setting the number of labels that will be attempted if an error occurs (set with ^RS).

• SGD Command (Set, Get, Do): An instruction sent to the printer to set or get configuration details (ex. configure the printer language). These commands allow a user to configure printers with firmware versions V60.15.xZ, V50.15.xZ, V61.15.xZ, V56.15.xZ, V53.15.xZ, or later. The printer performs the specified function immediately after receiving the command. Commands are case sensitive. The 3 types of commands are: setvar, getvar and do. Ex. ! U1 setvar “device.languages” “zpl”

• Zebra's Best Practices Document: A document outlining Zebra’s recommendations on how to build a best in class application. It includes minimum functional requirements and best.

Page 6: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Zebra’s Best Practices

6

6

• Printer does not need special set up to work with app

App interfaces with printer out of the box

• The app will not freeze, lockup, or crash when interacting with the printer such as attempting to communicate with the printer and encountering the common error cases listed below.

• Printer unreachable by the client.

• Printer is out of media.

• Printer media door is left open.

Stability 稳定性

• The app produces the expected printed output with acceptable print quality.

Printed Output 打印输出

• The application will check and set the language of the printer (ZPL, Line Mode, CPCL, etc.).

Check Printer Formatting Language 检查打印机语言

• The application will check the status of the printer before sending a print-job. Once the printer verifies the printer is not in an error state, the print job can be sent.

Check Printer Status 检查打印机状态

• All apps must alert the user if the printer is unreachable or in any other error states before sending a print job. The app should be specific about the error state that the printer is in. ie. Out of paper, door open, etc.

Display Printer Error Status 显示打印机的错误信息

• Verify that, if present, usage of Zebra printer branding (logo, model number, etc.) meets Zebra Technologies Global Brand Standards.

Proper Zebra Branding 适当使用斑马的标志

Page 7: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Zebra’s Best Practices

• New functionality and features are being focused exclusively on ZPL.

Use ZPL for label formatting

使用ZPL去构建标签格式

• Graphic data is generally larger file size. It also introduces risk of distortion & unreadable barcodes.

• Static images, such as logos, should be stored in printer memory and recalled at time of print.

Print Graphics Only When Necessary

仅仅只当需要的时候才去打印图片

Page 8: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Concepts of Printing with Zebra

Devices

Page 9: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Concepts of Printing with Zebra Devices - Connectivity

• Set up Connectivity /Discovery • Bluetooth (3.0/4.0) • WIFI (802.11a/b/g/n) • NFC (Except for Apple)

WLAN connectivity supports both 2.4GHz and 5GHz bands and roaming within and across bands.

The multiport radio can simultaneously operate 802.11a/b/g/n and Bluetooth 3.0

Print Touch enables new experiences and quick access to helpful information. Print Touch devices offer app and web page launching features

Page 10: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Concepts of Printing with Zebra Devices

• Check and Select the Print Language 检查和选择打印机语言

• ZPL

• CPCL

• LINE PRINT

Page 11: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Concepts of Printing with Zebra Devices

• Check and Select the Printer Language

检查和选择打印机语言

• ZPL

• CPCL

• LINE PRINT

Page 12: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Concepts of Printing with Zebra Devices

• Check and Select the Printer Language

检查和选择打印机语言

• ZPL

• CPCL

• LINE PRINT

Page 13: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Concepts of Printing with Zebra Devices – Common Issues

• Check Status/Display Errors

检查状态/显示错误 • No connection 连接不上 • Door Open 盖子打开 • Out of Media 无纸

• Data Loss

数据丢失

• Apps do not print correctly

应用程序打印不正确

• App freezes/crashes(30%)

应用程序崩溃

• Poor User experience

不好的用户体验

No Connection

Display Error Message

Door Open Out of Media

Page 14: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Concepts of Printing with Zebra Devices – Common Use Cases • Send “ZPL format to print”

• Print of a Image (JPG/PNG) • Select an image on Mobile Device • Send to print image selected

• Signature Capture – Dynamic capture of signature on

Android Device

– Send image of signature to print

• Receipt – Input Data

– Dynamic addition to ZPL format – Send to print

• Store Format – Selecting ZPL file

– Store ZPL file in Zebra Printer

Page 15: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Printing with Android Devices API Overview

Page 17: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Packages Description Interfaces Classes Enums Exceptions 1 com.zebra.sdk.comm Provides implementation for

communication protocols.

6 12 1 2

2 com.zebra.sdk.device Provides implementation for

device operations

6 4 0 1

3 com.zebra.sdk.graphics Provides implementation for

working with graphics

formatted for a Zebra printer.

1 1 0 0

4 com.zebra.sdk.printer Provides implementation for

Zebra branded printer

functionality.

14 16 4 3

5 com.zebra.sdk.printer.discovery Provides implementation for

finding Zebra branded printers.

3 9 0 1

6 com.zebra.sdk.settings Provides implementation for

applying and retrieving

settings from a device.

1 1 2 1

7 com.zebra.sdk.weblink Provides implementation for

Weblink configuration.

0 2 3 1

Total 31 45 10 9

API Overview – API For Android (build V2.8.2148)

Page 18: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Communication com.zebra.sdk.comm

Provides Implementation for communications protocols.

API Overview – API For Android (build V2.8.2148)

Page 19: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

API Overview – API For Android (build V2.8.2148) Communication com.zebra.sdk.comm

Provides Implementation for communications protocols.

Page 20: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

API Overview – API For Android (build V2.8.2148) Communication com.zebra.sdk.comm

Provides Implementation for communications protocols.

Page 21: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

API Overview – API For Android (build V2.8.2148) Communication com.zebra.sdk.device

Provides Implementation for devices operations

Page 22: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

API Overview – API For Android (build V2.8.2148) Communication com.zebra.sdk.device

Provides Implementation for devices operations

Page 23: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

API Overview – API For Android (build V2.8.2148) Communication com.zebra.sdk.graphics

Provides Implementation for working formatted for a Zebra Printer

Page 24: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

API Overview – API For Android (build V2.8.2148) Communication com.zebra.sdk.printer

Provides Implementation for Zebra branded printer functionality

Page 25: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

API Overview – API For Android (build V2.8.2148) Communication com.zebra.sdk.printer

Provides Implementation for Zebra branded printer functionality

Page 26: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

API Overview – API For Android (build V2.8.2148) Communication com.zebra.sdk.printer

Provides Implementation for Zebra branded printer functionality

Page 27: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

API Overview – API For Android (build V2.8.2148) Communication com.zebra.sdk.discovery

Provides Implementation for finding Zebra branded printers

Page 28: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

API Overview – API For Android (build V2.8.2148) Communication com.zebra.sdk.discovery

Provides Implementation for finding Zebra branded printers

Page 29: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

API Overview – API For Android (build V2.8.2148) Communication com.zebra.sdk.settings

Provides Implementation for applying and retrieving settings from a device.

Page 30: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

API Overview – API For Android (build V2.8.2148) Communication com.zebra.sdk.weblink

Provides Implementation for applying and retrieving settings from a device.

Page 31: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Printing with Android Devices Build an App

Page 32: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Build an App – Logic for Sample Receipt 1. Discover Printers

发现打印机

2. Select and Connect the printer 选择和连接打印机

3. Check and Setup Language to “ZPL” 检查和设置打印机语言为“ZPL”

4. Store the “ZPL format to print” with logo in Printer 存储“ZPL格式”的打印模板和商标在打印机里

5. Input Dynamic data 输入动态数据

6. Create an image with Signature Capture 创造一个捕获签名的图片

7. Store the image with Signature in Printer 把签名图片存储在打印机里

8. Check for status before to print 打印之前查询打印机的状态

9. Recall ZPL format and print 调用ZPL模板和打印

10. Close connection 关闭连接

Page 33: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Build an App – Getting Started

Getting Started with Android Development – Zebra Android Link-OS SDK - Java – Android Studio

https://km.zebra.com/kb/index?page=content&id=WH132

Overview

This Application Note describes the end to end process of designing, packaging, deploying and running an Android application using the Zebra Link-OS™ Multiplatform SDK and Smartphone Utility.

The sample code used in this Application Note is from the sample code article Connect and Print Over TCP/IP and Bluetooth – Zebra Android Link-OS™ SDK – Java – Android Studio.

Target Audience

The information in this document assumes that you have technical competence with Microsoft Windows, Java development with the Android Studio Integrated Development Environment (IDE), and core programming concepts and rationales.

Page 34: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Build an App – Demo’s Structure

Page 35: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

try {

BluetoothDiscoverer.findPrinters(getActivity(), new

DiscoveryHandler() {

@Override

public void foundPrinter(DiscoveredPrinter discoveredPrinter) {

discoveredPrinters.add(discoveredPrinter);

adapter.notifyDataSetChanged();

Log.i(TAG, "Discovered a printer");

}

@Override

public void discoveryFinished() {

Log.i(TAG, "Discovery finished");

}

@Override

public void discoveryError(String s) {

Log.i(TAG, "Discovery error");

}

});

} catch (ConnectionException e) {

Log.i(TAG, "Printer connection error");

}

Build an App – Discover Printers Bluetooth Discovery

Page 36: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Build an App – Select and Connect The Printer public class SelectedPrinterManager {

private static DiscoveredPrinter currentlySelectedPrinter = null;

public static DiscoveredPrinter getSelectedPrinter() {

return currentlySelectedPrinter;

}

public static void setSelectedPrinter(DiscoveredPrinter selectedPrinter) {

SelectedPrinterManager.currentlySelectedPrinter = selectedPrinter;

}

public static String getFriendlyName() {

String friendlyName = "";

if (currentlySelectedPrinter != null) {

friendlyName = currentlySelectedPrinter.getDiscoveryDataMap().get("SYSTEM_NAME");

}

return friendlyName;

}

public static String getMacAddress() {

String macAddress = "";

if (currentlySelectedPrinter != null) {

macAddress = currentlySelectedPrinter.getDiscoveryDataMap().get("HARDWARE_ADDRESS");

}

return macAddress;

}

Page 37: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Build an App – Check/Setup Language to “ZPL”

if (printerStatus.isReadyToPrint) {

snackbarMsg = mainActivity.getString(R.string.print_successful);

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

if (printerConnection.isConnected()) {

try {

printer = ZebraPrinterFactory.getInstance(printerConnection);

setStatus("Determining Printer Language", Color.YELLOW);

PrinterLanguage pl = printer.getPrinterControlLanguage();

setStatus("Printer Language " + pl, Color.BLUE);

} catch (ConnectionException e) {

setStatus("Unknown Printer Language", Color.RED);

printer = null;

DemoSleeper.sleep(1000);

disconnect();

} catch (ZebraPrinterLanguageUnknownException e) {

setStatus("Unknown Printer Language", Color.RED);

printer = null;

DemoSleeper.sleep(1000);

disconnect();

}

}

Check Printer Language

Setup Printer Language

Page 38: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Build an App – Store the “ZPL format” in Printer

if (discoveredPrinter != null) {

Connection = new BluetoothConnection(discoveredPrinter.address);

try {

connection.open();

ZebraPrinter zebraPrinter = ZebraPrinterFactory.getInstance(connection);

PrinterStatus printerStatus = zebraPrinter.getCurrentStatus();

String snackbarMsg;

byte[] configReceipt = TEMPLATE_ZPL.getBytes();

if (printerStatus.isReadyToPrint) {

snackbarMsg = mainActivity.getString(R.string.print_successful);

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

try {

// zebraPrinter.calibrate();

connection.write(configReceipt);

zebraPrinter.storeImage("Signature.GRF", new ZebraImageAndroid(signatureBitmap), -1, -1);

zebraPrinter.printStoredFormat("E:SampleRe.ZPL", mainActivity.mergeVariables());

} catch (ZebraIllegalArgumentException e) {

}

Page 39: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Build an App – Input Dynamic(Static for demo) Data

public HashMap<Integer, String> mergeVariables() {

int taxInCents = Math.round((productOnePriceTotalCents + productTwoPriceTotalCents) * 9 / 100);

HashMap<Integer, String> variableMap = new HashMap<>();

variableMap.put(16, getString(R.string.product_2));

variableMap.put(22, formatPrice(productTwoPriceTotalCents));

variableMap.put(13, getString(R.string.product_1));

variableMap.put(15, Integer.toString(productTwoQuantityInt));

variableMap.put(19, formatPrice(productOnePriceTotalCents));

variableMap.put(11, Integer.toString(productOneQuantityInt));

variableMap.put(20, formatPrice(productOnePriceTotalCents + productTwoPriceTotalCents + taxInCents));

variableMap.put(14, ";786781346413>61");

variableMap.put(21, formatPrice(taxInCents));

variableMap.put(24, ":4:18");

variableMap.put(23, "150916");

variableMap.put(18, ";851346>61");

variableMap.put(17, ";794613>64");

variableMap.put(12, ";464316461346>61");

return variableMap;

}

Page 40: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Build an App – Create an image with Signature Capture

ackage com.zebra.appforumsignaturecapturedemo;

import android.content.Context;

import android.graphics.Bitmap;

import android.graphics.Canvas;

import android.graphics.Color;

import android.graphics.Paint;

import android.util.AttributeSet;

import android.view.MotionEvent;

import android.view.SurfaceHolder;

import android.view.SurfaceView;

public class SignatureArea extends SurfaceView implements SurfaceHolder.Callback {

public SignatureArea(Context context) {

this(context, null);

}

public SignatureArea(Context , AttributeSet attrs) {

super(context, attrs);

SurfaceHolder holder = getHolder();

holder.addCallback(this);

setFocusable(true); // make sure we get key events

black = new Paint();

black.setColor(Color.BLACK);

black.setStyle(Paint.Style.STROKE);

black.setStrokeWidth(5);

setWillNotDraw(false);

}

Page 41: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Build an App – Store the Image with Signature in Printer

if (discoveredPrinter != null) {

Connection = new BluetoothConnection(discoveredPrinter.address);

try {

connection.open();

ZebraPrinter zebraPrinter = ZebraPrinterFactory.getInstance(connection);

PrinterStatus printerStatus = zebraPrinter.getCurrentStatus();

String snackbarMsg;

byte[] configReceipt = TEMPLATE_ZPL.getBytes();

if (printerStatus.isReadyToPrint) {

snackbarMsg = mainActivity.getString(R.string.print_successful);

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

try {

// zebraPrinter.calibrate();

connection.write(configReceipt);

zebraPrinter.storeImage("Signature.GRF", new ZebraImageAndroid(signatureBitmap), -1, -1);

zebraPrinter.printStoredFormat("E:SampleRe.ZPL", mainActivity.mergeVariables());

} catch (ZebraIllegalArgumentException e) {

}

Page 42: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Build an App – Check for status before to print

}

} else if (printerStatus.isPaused) {

snackbarMsg =

mainActivity.getString(R.string.print_failed) + " " +

mainActivity.getString(R.string.printer_paused);

} else if (printerStatus.isHeadOpen) {

snackbarMsg =

mainActivity.getString(R.string.print_failed) + " " +

mainActivity.getString(R.string.head_open);

} else if (printerStatus.isPaperOut) {

snackbarMsg =

mainActivity.getString(R.string.print_failed) + " " +

mainActivity.getString(R.string.paper_out);

} else {

snackbarMsg =

mainActivity.getString(R.string.print_failed) + " " +

mainActivity.getString(R.string.cannot_print);

}

mainActivity.showSnackbar(snackbarMsg);

} catch (ZebraPrinterLanguageUnknownException e) {

} catch (ConnectionException e) {

mainActivity.showSnackbar(mainActivity.getString(R.string.

connection_error));

} finally {

try {

connection.close();

} catch (ConnectionException e) {

}

Page 43: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Recommendation

During the development, you can go to the Zebra Developer Community at http://developer.zebra.com when you have any questions. We have blogs, forums, and links to sample code and other documents there.

Page 44: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

THANK YOU

Page 45: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Appendix

Page 46: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Systems Elements – Layers of Control

46

Formatting

ZPL, EPL,CPCL, APL-I, APL-D WML

Configuration

SGD, JSON, SNMP, XML, HTML

Data Manipulation

ZBI

Communication

Serial, Parallel, USB, Ethernet, WLAN, Bluetooth

APPLICATIONS

Page 47: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Recall ZPL format and print

~DG000.GRF,271360,212, ,:::::jO07FLF80M01FFC0gI03FNFV01FFC0gI0HFE0X03FF80gH01FIFE0hV07FF0,I07FiGF80gG07FLF80M01FFC0gI03FNFV01F

^FT64,1312^XG000.GRF,1,1^FS

^XA^ID000.GRF^FS^XZ

Downloading a ZPL Format(^DFR) Re-calling a ZPL template (^XFR)

Downloading a graphic (~DG)

Recalling the graphic(^XG)

Deleting the graphic created dynamically(^ID)

ZPL Programming Guide

Page 48: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

SampleRe Template CT~~CD,~CC^~CT~ ^XA ^DFE:SampleRe.ZPL^FS ~TA000^MNN^MTT^POI^PMN,0^JMA^PR6,6^MD15^LRN^CI0 ^MMT ^PW574 ^LL0508 ^LS0 ^FO0,0^GFA,01536,01536,00012,:Z64: eJzd0jtyHCEQBuDBBDhwGZ9g8RF0AGnwUXQEhQpYw5buYcW+xWwpcKgjCJUuwJYTpB0P7m6ezu3ERF9NMf13A9P0jxZ3g/3gOHitEoOV41u1XrqV75aRp/Zv9zu+tj2Cbd0u3VXLxXZ7/VBzZVAvtTcR5Tm0JsV5KYaSqfWQWGo9WJdSGfiLXmwqP1wrb1MZ/kaCS9EovHlffl25Nx+KN/DHWh4sa/k7cKmvH7rVC7iEyZ/gpxwmzuDHHMYT+EeejKHrxOjSp0MfsxeNzgFeofOmING5fiSH1r88xtZ/dWLd1pE19b9ckzFB+c9kTJBhImOCiNmRzr+bbdNXeYia7iBNFnbm+7DOumq9QL1iBROAaWIZIIJniyjQ1B28mQAnQ9PABQc8mTzBFLBamaC+B/x00ax8t+xbcIK2+tOmCfpKg63rLpkloPuPgMF8MBs8jb4ZfDH40/R/L/2a7lfr6amjNxsV2p662cnvZrPSWbNnv9sZQ+bkyyvyMcAec4VnKo5Q06yGfEj30cZbtDxgzXCLl68Y/Gu9rVbW03ub0ftA73D+/vZt3p/e1tqPeQ2Xzb/8DE7PUN/syX9//QZjPS7w:EBC1 ^FO250,380^XGSignature.GRF,1,1^FS ^FO196,358^GB253,99,8^FS ^FT110,36^A0N,31,31^FH\^FDZebra Technologies Corp.^FS ^FT109,70^A0N,17,16^FH\^FD3 Overlook Point, Lincolshire, IL, 60029^FS ^FT109,91^A0N,17,16^FH\^FDAppForum - Las Vegas - 2015^FS ^FT109,112^A0N,17,16^FH\^FDSample Receipt^FS ^FT8,164^A0N,23,24^FH\^FDProduct:^FS ^FT197,163^A0N,23,24^FH\^FDPrice :^FS ^FT290,476^A0N,13,12^FH\^FDSign Here^FS ^FT342,163^A0N,23,24^FH\^FDQTY:^FS ^FO8,260^GB549,0,7^FS ^FO8,135^GB550,0,6^FS ^FT8,331^A0N,23,24^FH\^FDTOTAL :^FS ^FT8,245^A0N,23,24^FH\^FN16"FProduct2"^FS ^FT197,244^A0N,23,24^FH\^FN22"FPrice2"^FS ^FT8,208^A0N,23,24^FH\^FN13"FProduct"^FS ^FT351,241^A0N,23,24^FH\^FN15"Fqty2"^FS ^FT197,206^A0N,23,24^FH\^FN19"FPrice"^FS ^FT350,205^A0N,23,24^FH\^FN11"Fqty"^FS ^FT198,331^A0N,23,24^FH\^FN20"FTotal"^FS ^FT9,300^A0N,23,24^FH\^FDTAX :^FS ^BY1,3,23^FT433,240^BCN,,N,N,N,A ^FN14"ProductBarcode2"^FS ^FT198,297^A0N,23,24^FH\^FN21"FTax"^FS ^BY2,3,23^FT6,438^BCN,,N,N,N,A ^FN24""^FS ^BY2,3,23^FT7,398^BCN,,N,N,N,A ^FN23""^FS ^BY1,3,23^FT470,431^BCN,,N,N,N,A ^FN18"TruckBarcode"^FS ^BY1,3,23^FT470,391^BCN,,N,N,N,A ^FN17"DriverBarcode"^FS ^BY1,3,23^FT432,206^BCN,,N,N,N,A ^FN12"ProductBarcode"^FS ^FT448,127^BQN,2,5 ^FDMA,www.zebra.com^FS ^XZ

Page 49: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

SampleRe Data

^XA ^XFE:SampleRe.ZPL ^FN16^FDCharger^FS ^FN22^FD$100.00^FS ^FN13^FDZebra TC55^FS ^FN15^FD1^FS ^FN19^FD$580.00^FS ^FN11^FD1^FS ^FN20^FD$741.20^FS ^FN14^FD;786781346413>61^FS ^FN21^FD$ 61.20^FS ^FN24^FD:4:18^FS ^FN23^FD150916^FS ^FN18^FD;851346>61^FS ^FN17^FD;794613>64^FS ^FN12^FD;464316461346>61^FS ^XZ

Page 50: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

Printing with Android Devices Setup

Page 53: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

LINK-OS SDK Initial Setup to Import Zebra demo in Android Studio

• Importing Example Code into Android Studio

• Navigate to [Platform]/[build version]/demos/eclipse within your Link-OS Multiplatform SDK installation directory (where [Platform] is the desired platform and [build version] corresponds to the desired build)

• Unzip the archive into a new folder on your file system

• From the Android Studio menu bar, select File > Import Project...

• Navigate to the folder with the unzipped archive contents

• Click the OK button • Click the Next button • Click the Finish button

Page 54: Printing with Android Devices - Zebra Technologieslaunchpad.zebra.com/apac_appforum2015/workshops/... · Zebra branded printer functionality. 14 16 4 3 5 com.zebra.sdk.printer.discovery

LINK-OS SDK Initial Setup to Import Zebra demo in Android Studio

• Open build.gradle file and import the following libraries.

packagingOptions { exclude 'META-INF/DEPENDENCIES.txt' exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/dependencies.txt' exclude 'META-INF/LICENSE.txt' exclude 'META-INF/LICENSE' exclude 'META-INF/license.txt' exclude 'META-INF/LGPL2.1' exclude 'META-INF/NOTICE.txt' exclude 'META-INF/NOTICE' exclude 'META-INF/notice.txt' } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile "com.android.support:support-v4:18.0.+" compile files('libs/commons-io-2.2.jar') compile files('libs/commons-net-3.1.jar') compile files('libs/commons-validator-1.4.0.jar') compile files('libs/httpcore-4.3.1.jar') compile files('libs/httpmime-4.3.2.jar') compile files('libs/jackson-annotations-2.2.3.jar') compile files('libs/jackson-core-2.2.3.jar') compile files('libs/jackson-databind-2.2.3.jar') compile files('libs/opencsv-2.2.jar') compile files('libs/snmp6_1.jar') compile files('libs/ZSDK_ANDROID_API.jar') }