Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print to local shared printer on lan in android

Tags:

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

like image 655
DEVANG SHARMA Avatar asked Jan 20 '23 17:01

DEVANG SHARMA


2 Answers

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();
    } 
like image 177
ReachmeDroid Avatar answered Jan 22 '23 07:01

ReachmeDroid


One solution is using Google Cloud print with android

like image 35
Reno Avatar answered Jan 22 '23 07:01

Reno