简体   繁体   中英

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.

my printer IP is 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. The simplest way to connect via telnet or socket and write the data to their socket buffers.

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打印

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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