Reputation: 45
I am working on a android project. One key requirement is to print receipt via a wifi-connected printer.
At this stage, what I have achieved is to open a printer dialog. Then the printer dialog allows user to interact to select a list of available printers and then tap print.
But I hope there is a way to avoid user interaction and directly print the content like html file, image etc.
this is the code for printing a bitmap image.
private void doPhotoPrint()
{
PrintHelper photoPrinter = new PrintHelper(this);
photoPrinter.setScaleMode(PrintHelper.SCALE_MODE_FIT);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.coffeehost);
photoPrinter.printBitmap("droids.jpg - test print", bitmap);
}
and the printer is Epson Artisan 730.
The code works but it pops up a print dialog and user have to select the Epson printer and then tap "print" button.
What I really want is to avoid that dialog and directly print the image.
For this project, I can decide what kind of printer to use as long as it supports direct printing.
Upvotes: 0
Views: 831
Reputation: 45
I found one solution.
We can directly connect to the port the printer is using.
for example, my printer is listening at port 9100 and its address is 192.168.0.10. So we can connect to the 192.168.0.10:9100 using TCP protocol and then send your text to the socket. The printer will immediately print the content.
Upvotes: 1