简体   繁体   English

在android中的局域网上打印到本地共享打印机

[英]Print to local shared printer on lan in android

I develop an application which has several tasks like report generator, show history etc, 我开发了一个应用程序,它有几个任务,如报告生成器,显示历史等,

now I want to add a method by which I can directly print these report from the printer on local network. 现在我想添加一种方法,通过该方法我可以从本地网络上的打印机直接打印这些报告。

so I need that there is a Button named "Print" now when user click this button then my given text is directly print from the shared printer in local network by wifi connection. 所以我需要现在有一个名为“打印”的按钮,当用户单击此按钮时,我的给定文本将通过wifi连接从本地网络中的共享打印机直接打印。

my printer IP is 192.168.1.50 我的打印机IP是192.168.1.50

Now How i can do this by coding. 现在我如何通过编码来做到这一点。

please reply 请回复

Thanks 谢谢

Any device connected to a network will communicate via their IP and Ports / sockets. 连接到网络的任何设备都将通过其IP和端口/插槽进行通信。 The simplest way to connect via telnet or socket and write the data to their socket buffers. 通过telnet或socket连接并将数据写入其套接字缓冲区的最简单方法。

try 
    {
    Socket sock = new Socket("192.168.1.222", 9100);
    PrintWriter oStream = new PrintWriter(sock.getOutputStream());
        oStream.println("HI,test from Android Device");
        oStream.println("\n\n\n");
        oStream.close();
        sock.close(); 
    }
    catch (UnknownHostException e) 
    {
        e.printStackTrace();
    } 
    catch (IOException e) 
    { 
        e.printStackTrace();
    } 

一种解决方案是使用带有android的Google Cloud打印

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM