Android 4.2 - Printing using network printer

1.6k views Asked by At

I need a print a receipt from a receipt printer(network printer) via my android application which is developed by 4.2 version. is Android 4.2 support printing from the network printer? can any one please point me to a correct tutorial. Thanks

1

There are 1 answers

1
Manish Goswami On

device connected to a network will communicate via their IP and Ports / sockets.

    try 
   {
    Socket sock = new Socket("IP", port);
    PrintWriter oStream = new PrintWriter(sock.getOutputStream());
    oStream.println("");
    oStream.println("");
    oStream.close();
      sock.close(); 
  }
  catch (UnknownHostException e) 
 {
     e.printStackTrace();
 } 
 catch (IOException e) 
 { 
    e.printStackTrace();
  } 

how to print :

     private void doPrint() {
PrintManager printManager = (PrintManager) getActivity().getSystemService(Context.PRINT_SERVICE);
printManager.print("My document", new CustomPrintDocumentAdapter(getActivity()), null);
     } 

where CustomPrintDocumentAdapter extendsPrintDocumentAdapter

and more info about prnting Android Devlprs

more details Refer.