我试图连接局域网打印机以使用Windows假脱机程序,但我无法连接到地址localhost /打印机...... 我试图找到解决方案,但我发现只是使用LPT1和IP ...我需要使用Windows后台程序来打印文档,这对我来说很难,我实习并且不懂很多java语言...如果有人可以帮助我将apreciate .... 当我使用打印机IP(192.168.15.140)时,应用程序打印正常,但当我尝试使用localhost / printer时,java会返回此错误:
07-12 16:19:13.921 17939-17939 / com.example.dev_03.testeconnsqlsrv W / art:在Android 4.1之前,方法int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(INT, boolean)会错误地重写package-private方法 在android.widget.ListView
中07-12 16:19:15.066 17939-17939 / com.example.dev_03.testeconnsqlsrv W / System.err:java.net.UnknownHostException:无法解析主机 “192.168.15.12/PEDIDO”:没有与主机名相关联的地址
public class PrinterSpooler extends AsyncTask<String, String, String> {
public void Imprimir() {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
try {
Socket sock = new Socket("192.168.15.12/PEDIDO", 9100);
PrintWriter oStream = new PrintWriter(sock.getOutputStream());
oStream.println("HI,test from Android Device");
oStream.println("\n TESTANDO IMPRESSORA PELA API DO ANDROID STUDIO E VENDO A QUEBRA AUTOMATICA DE LINHA");
oStream.println("\n\n\n");
oStream.println("\n\n\n");
oStream.println("\n\n\n");
oStream.close();
sock.close();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
protected String doInBackground(String... strings) {
return null;
}
}