Printing to a local shared printer on a LAN in Android

I am developing an application that has several tasks, such as a report generator, browsing history, etc.

Now I want to add a method by which I can directly print this report from a printer on the local network.

so I need the button to now be called "Print" when the user clicks this button, then my text is directly printed from a shared printer on the local network via a Wi-Fi connection.

my printer IP is 192.168.1.50

Now how can I do this by coding.

answer

thanks

+4
source share
2 answers
+4
source

Any device connected to the network will communicate through its IP addresses and ports / sockets. The easiest way to connect via telnet or socket and write 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(); } 
+5
source

All Articles