是否可以在android编程中无需用户交互的情况下直接将内容打印到连接wifi的打印机? [英] Is it possible to directly print content to a wifi-connected printer without user interaction in android programming?

查看:72
本文介绍了是否可以在android编程中无需用户交互的情况下直接将内容打印到连接wifi的打印机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 android 项目.一个关键要求是通过连接 wifi 的打印机打印收据.

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.

但我希望有一种方法可以避免用户交互并直接打印html文件、图像等内容

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);
}

打印机是 Epson Artisan 730.

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.

推荐答案

我找到了一个解决方案.

I found one solution.

我们可以直接连接到打印机使用的端口.

We can directly connect to the port the printer is using.

例如,我的打印机正在侦听端口 9100,其地址是 192.168.0.10.所以我们可以使用 TCP 协议连接到 192.168.0.10:9100,然后将您的文本发送到套接字.打印机将立即打印内容.

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.

这篇关于是否可以在android编程中无需用户交互的情况下直接将内容打印到连接wifi的打印机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆