Basic Steps for Printing a Label

In the Java Printing library, the LabelPrinter class represents a label printer and provides methods to communicate with the printer. To print a label, the application needs to perform the following steps:

  1. Create an AsyncTask or a thread to invoke the printing API.

Android OS displays the "Application Not Responding" (ANR) message if the application performs a lengthy operation (about 5 seconds) on the UI thread. While this occurs, the system cannot process incoming user input events. The printing API communicates with the printer through a network connection, which may invoke unpredictable delays that result in the ANR message.

To prevent the ANR message, the LabelPrinter constructors and methods must be called on a separate thread on the Android platform. The only exceptions are the methods that add or remove an event listener. Most LabelPrinter methods throw a LabelPrinterException if called from the UI thread.

  1. Create label definitions.
  2. Create printer settings.
  3. Create a LabelPrinter object with parameters to specify the printer and the communication method.
  4. (Optional) Add event listeners to the LabelPrinter object.
  5. Connect to the printer.
  6. Print a label. You can repeat this step many times to print multiple labels.
  7. Disconnect from the printer and release the resources used by the LabelPrinter object.

Sample Code

Sample code is included in the Print a Label section. The Honeywell Mobility Android Printing SDK also includes a sample application called LabelPrinterSample.