Android Question Print to Zebra Thermal Printer from Android (B4A) on LAN

Mark Stuart

Active Member
Licensed User
Longtime User
Hi y'all,

I've searched the forum for printing to a Zebra printer from an android device, and have not found anything that works for my situation.
Situation:
Build B4A app that selects inventory items. The user then prints those items to the Zebra printer which is connected to the LAN, via USB to OTG cable. This will be the customers hardware setup.

I see there are lots of posts for BT connection, but that will not be the case for my customers multiple locations.
For testing purposes, my setup is such: the Zebra printer is connected to the desktop PC with the USB to OTG cable.
I need the Android device to recognize that printer and connect to it for print testing.
With my setup, I have not gotten past getting to connect to the printer or even the GetDevices function to see any devices.
And the customers setup will be different again, as described above.

The Data:
What will be printed on the label consists of inventory information such as PLU, Description, PLU printed as the Barcode, and Price. This data is downloaded to the device with JSON data to the local SQLite database. ZPL will be sent to the printer with the item data.
The labels are a 2-up (2 across) Zebra labels, if that makes a difference, but shouldn't.

Libraries Tried:
I've tried a number of libraries: RandomAccessFile, UsbSerial, Network, and USB, using examples from the forum.
But none will recognize the Zebra printer. I'm obviously doing it all wrong, as the posting people says it's working.

I've considered the Printing library but I don't know if it will send the ZPL data to the printer.

So I need help big time to connect to the printer and print ZPL to it.

Regards,
Mark Stuart
 

aeric

Expert
Licensed User
Longtime User
Upvote 0

Mark Stuart

Active Member
Licensed User
Longtime User
I looked all over the forum, and I'm familiar with that library, but it doesn't suit my project.

Currently, I'm looking to Zebra with their SDK.
Maybe they know how to do this.
 
Upvote 0

f0raster0

Well-Known Member
Licensed User
Longtime User
Upvote 0

Mark Stuart

Active Member
Licensed User
Longtime User
Upvote 0

f0raster0

Well-Known Member
Licensed User
Longtime User
Star-Dust's lib doesn't work?
 
Upvote 0

Mark Stuart

Active Member
Licensed User
Longtime User
the library of Star-Dust doesn't work?
As I responded to another post, it is not suited to my project.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
A few years ago I created option 1, to print on Zebra printers connected to a PC.
Option 1: If you use Zebra with **ZPL** (very common):

1. Android generates the **ZPL** or **PDF** file.
2. Sends it via:

* HTTP

* Socket

* Shared folder
3. A program on your PC:

* Reads the file

* Sends it to the Zebra printer

Widely used in inventory and POS systems.

---

Option 2: PrinterShare (the simplest)

If you want something quick without programming:

On your PC:

1. Install **PrinterShare Desktop**
2. Share the Zebra printer

On Android:

1. Install **PrinterShare**
2. Connect via Wi-Fi
3. Print from the app

Limitations:

* Watermark in the free version
* Not ideal for high-volume printing
* May fail with complex labels

Test option 2:
 
Last edited:
Upvote 0

Mark Stuart

Active Member
Licensed User
Longtime User
A few years ago I created option 1, to print on Zebra printers connected to a PC.
Hello, thank you for your respone.

I'm moving forward with 2 connection methods: a BT connection and a USB/OTG direct cable connection from the device to the printer. The latter method I'll be testing tomorrow with a USB-A to USB-C converter.

The customer has older (no BT) printers, so that's where the direct cable connection will be employed.
Maybe I'll offer the LAN method at a later date.
The BT method will be for locations that want to upgrade their equipment and possibly use an Android cell phone for printing labels.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Direct printing via USB, LAN (Wi-Fi), etc., is simple; complex printing occurs when printers are connected to a PC as slaves. Mobile devices will not see them even if they are shared, unless you use or develop with Zebra's SDK.

ex (socket).


test:
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Direct printing via USB, LAN (Wi-Fi), etc., is simple; complex printing occurs when printers are connected to a PC as slaves. Mobile devices will not see them even if they are shared, unless you use or develop with Zebra's SDK.

ex (socket).


test:
To create a bridge between your app and the slave printers on a PC, you can use, for example, this:

A server printer app on your PC
 
Upvote 0

Mark Stuart

Active Member
Licensed User
Longtime User
Thank you for the links. I'll take a look.

I'm taking a keep-it-simple approach to this printing solution as for now.
Maybe when the customer starts using it and sees the benefit, they'll look for other approaches.
Meanwhile, it's a BT and direct cable approach.
 
Upvote 0

Mark Stuart

Active Member
Licensed User
Longtime User
Hi Aeric,
And how much would that cost for each location, not only in hardware but in time to maintain it?
I don't think their IT dept. would go for it. Besides, there are 20 locations that this would have to cover.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Hi Aeric,
And how much would that cost for each location, not only in hardware but in time to maintain it?
I don't think their IT dept. would go for it. Besides, there are 20 locations that this would have to cover.
You mean the RaspberryPi?
No, you don't need it. By the way, RPi is cheaper than a PC.
You can use any desktop as a server. Windows, Linux, macOS, it is up to you.
For testing purposes, my setup is such: the Zebra printer is connected to the desktop PC with the USB to OTG cable.
Since you have already able to connect the printer to a PC.
The Android app can just connect to the server using the server IP. The app doesn't need to detect it.
It just connect like a client-server app. You can make http POST with JSON data.
You can see the video, the client can get the http 200 success status code response from the server too.
 
Upvote 0

Mark Stuart

Active Member
Licensed User
Longtime User
Maybe down the road if the customer has a need. But right now I'm trying to introduce new method for printing barcode labels, and it has to work as a simple change that benefits them.
Ease of use with something they use every day - a cell phone. That's where I'm trying to get them to.

10 years ago I built the customer a VB.NET Windows app that prints the barcodes. So this would be a change for sure. And there are 20 locations that use this. And a potential of 40 locations.
It's gotta work, with not too much change.

Thanx Aeric, I'll keep that in mind.

Mark
 
Upvote 0

DarkoT

Active Member
Licensed User
Hi, here’s an idea for solving this and similar problems.
In our company, we use Android-based handheld scanners. Various departments need to print different types of labels (product labels, shipping labels, customer-specific labels, with or without logos, etc.). We also have different types of printers across the production floor – Zebra, standard office printers, and high-speed industrial printers.

Since scanners are often moved between departments, we would normally have to manually reconfigure or install a new printer every time. To avoid this, I took a different approach. The Android client app doesn't handle printing at all; it simply sends the Report ID, number of copies, and the Device ID (where it needs to be printed).

On a Windows workstation, I installed a B4J application that acts as a 'Autoprint Server' = Automaticaly print server. Every x seconds, this app checks the SQL database for new print requests. When a request is found, the Autoprint server triggers, identifies the report type, quantity, and the target printer, and sends the job. Once successfully printed, the request flag is set to 'Printed'.

It’s fast, simple, and works perfectly. The entire solution is built on the B4X platform using JasperSoft for report generation. If anyone is interested in more details or wants the source code for the AutoPrint system, let me know. I'm happy to share the solution.
1767611134309.png



Best regards, Darko
 
Upvote 0

Bladimir Silva Toro

Active Member
Licensed User
Longtime User
Hi, if you have a printer connected to the LAN via Ethernet cable or Wi-Fi, you can use this code in B4A; it always works.

B4X:
Sub Process_Globals
    Dim TMT20II As Socket 'Network library
    Dim AStreams As AsyncStreams 'RandomAccessFile library
End Sub

Sub Activity_Create(FirstTime As Boolean)
    TMT20II.Initialize("TMT20II")
    TMT20II.Connect("192.168.0.100", 9100, 0) '100=Printer address, 9100=Port number (please look up port number)
End Sub

Sub TMT20II_Connected (Successful As Boolean)
    Log(Successful)
    If Successful Then
        AStreams.Initialize(TMT20II.InputStream, TMT20II.OutputStream, "AStreams")
        CallSub(Null, SendToPrinter)
    End If
End Sub

Sub SendToPrinter
    Dim SendMsg As String

    SendMsg = Chr(27) & Chr(61) & Chr(1) 'Select EPSON printer
    AStreams.Write(SendMsg.GetBytes("UTF8"))

    SendMsg = "Hello, this is a test print" 'Send this line to the EPSON printer
    AStreams.Write(SendMsg.GetBytes("UTF8"))

    SendMsg = Chr(27) & Chr(100) & Chr(2) 'Line feed
    AStreams.Write(SendMsg.GetBytes("UTF8"))

    SendMsg = Chr(27) & Chr(109) 'Partial cut receipt paper
    AStreams.Write(SendMsg.GetBytes("UTF8"))
End Sub

Remember to use the ESC/POS codes from the following link: https://escpos.readthedocs.io/en/latest/commands.html
 
Upvote 0

Mark Stuart

Active Member
Licensed User
Longtime User
Hi Bladimir,
3 things...
1. What do you suggest in the _Connected for a failed connection. You have no Else that handles maybe a retry connection for the user.
2. I'll be using ZPL for Zebra printers, not Epson printers, which I guess ESC/POS supports.
3. Have you considered putting this into a class?

EDIT: I'm working on a prototype app that will print to a Zebra printer that supports ZPL commands. Most of them do.
The app will print using all 3 connection methods: Bluetooth, USB cable, and WiFi.
I'll post it to the forum when all methods are complete and working.
Bluetooth and USB are complete and working.

Of course, the Zebra printer must support a Bluetooth Classic connection. Does not work with the BLE as far as I know.
The USB has to use a cable of course. One end is the USB Type-B and the other is typically a USB Type-C.
But my old cable has the USB Micro-B, so I had to buy the convertor connector.
 
Last edited:
Upvote 0
Top