I've read tons of similar questions and haven't gotten anywhere..
What I'm trying to do is connect to a printer directly by IP (not one that's in my windows devices list) and print a document to it.
Here's what I've tried so far (didn't work, no idea why):
try{
Socket sock = new Socket("1.2.3.4", 9100);
PrintWriter oStream = new PrintWriter(sock.getOutputStream());
oStream.println("Hello World");
oStream.close();
sock.close();
}
catch (UnknownHostException e){
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
I found this for your problem. You can try your network printer with this code.
https://blog.entelect.co.za/view/3213/android-printing-to-a-network-printer
I also saw many examples just like your example worked. So I guess there could be a connection problem to printer.
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.