Updated 26 October 2021
In this blog we will learn how to integrate EPSON POS Printer (Model starting with TM )with your android application.
Integrating this is not at all difficult, if you follow the steps correctly.
First, download the Epson sdk for android. (You can download the sdk from here).
Now from this package, extract the ePOS2.jar file and paste it in your libs folder.
Add this line in your build.gradle file.
1 |
compile files('libs/ePOS2.jar') |
Now all you have to do is make an object of the Printer and set the content that you want to print.
Lets have a look on how to do that.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
private Printer mPrinter; // Declare a global instance of Printer mPrinter = new Printer("REPLACE THIS STRING WITH YOUR PRINTER SERIES", "REPLACE THIS WITH YOUR PRINTER LANGUAGE", this);// Initialize the printer /*Add a listener to your printer*/ mPrinter.setReceiveEventListener(new ReceiveListener() { @Override public void onPtrReceive(Printer printer, int code, PrinterStatusInfo printerStatusInfo, String s) { if (code == Epos2CallbackCode.CODE_SUCCESS){ createMyData(); printMyData(); }else{ Toast.makeText(mContext, "Printer can't be connected. Please try again", Toast.LENGTH_SHORT).show(); } } }); |
createMyData()
1 2 3 4 5 6 7 8 9 10 11 12 13 |
private void CreateMyData() throws Epos2Exception { mPrinter.addTextAlign(Printer.ALIGN_CENTER);// by default the alignment is left. mPrinter.addFeedLine(1);// Calling this API causes the printer positioned at "the beginning of the line." StringBuilder builder = new StringBuilder(); builder.append("test content "); builder.append("\n"); builder.append("test content "); builder.append("\n"); mPrinter.addText(builder.toString()); /*Adds a sheet cut command "CUT THE SHEET" to the command buffer.*/ mPrinter.addCut(Printer.CUT_FEED); } |
printMyData()
1 2 3 4 5 6 |
private void printMyData() throws Epos2Exception { mPrinter.connect("REPLACE_THIS_STRING_WITH_THE_PORT_CONNECTION", Printer.PARAM_DEFAULT); mPrinter.beginTransaction(); mPrinter.sendData(Printer.PARAM_DEFAULT); } |
Please note that in printMyData(), you need to replace the first input with the target i.e you need to set the path of the connection or more specifically the port address of your printer.
That’s all
You can connect the printer and test it yourself.
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
10 comments
Basically it is the target port of the connected printer.
Before you request to print data you need to save the connected printer information with you and then from that information the value of the target filed needs to be passed in this function.
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file “/data/app/com.cmexpertise.instaorder-hogeXAYNRK-s_ihRSPwlBQ==/base.apk”],nativeLibraryDirectories=[/data/app/com.cmexpertise.instaorder-hogeXAYNRK-s_ihRSPwlBQ==/lib/arm64, /system/lib64, /product/lib64]]] couldn’t find “libepos2.so”
It seems that you have not multidex enabled in your project.
Once you enable the proguard in your project then you will have to do a trick with your code.
In the “jniLibs” directory of your project.
There will be one directory named “armeabi” or some other directory that contains a file named “libepos.so”
When you find this file then you need to take a copy of this file and make five directories under the “jniLibs” directory.
The names of these directories should be exactly :
arm64-v8a
armeabi
armeabi-v7a
x86
x86_64
In each of these directories, paste the “libepos.so” file in each of these directories.
Your final code should look like something like this –> http://i.prntscr.com/3vNb-25ySfKFWgfVWYRGnA.png
Hope this helps you.
If still, you are facing any issue, then please do let me know.
You just need to make sure that your android device and the printer are connected via the usb port .
You will need to make sure that the printer and android device are connected and in sync before giving any print command as explained in the blog above.
I downloaded the Java code to my Mac OS laptop, loaded it in android studio and installed it in my phone. I then connected the TMU220B to the USB port of a router and connected my phone to that router. It will not print..
So I went to the epson dealer and asked for a TMU220B with an internet port (not USB) and plugged that printer to my router. I then connected my phone to the same router and fixed the router settings to allow 192.168.192.168. This time I was able to print a receipt!
Am I correct to say that this TMU220 USB printer will only work with a Window computer that has the epson hardware driver and will not work if I connect it to a network router
I have integrated above code in my android app but app is not able to detect Epson TM_T82 printer, how can we achieve that please help. Thanks.
please go through the comments and see if this helps you.