Is it possible to directly print content to a wifi-connected printer without user interaction in android programming?

天涯浪子 提交于 2019-12-12 05:49:22

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/30449059/is-it-possible-to-directly-print-content-to-a-wifi-connected-printer-without-use

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!