[英]connect android device with printer and print document
I am developing an app in which I want to integrate print feature.Is it possible to send file to printer(for any company or brand) from app and print it. 我正在开发一个要集成打印功能的应用程序。是否可以从应用程序将文件发送到打印机(对于任何公司或品牌),然后进行打印。
so far googled and found following code but no luck. 到目前为止,谷歌搜索并发现以下代码,但没有运气。
try {
client = new Socket(ipAddress, port);
// create a byte array to file
byte[] mybytearray = new byte[(int) file.length()];
fileInputStream = new FileInputStream(file);
bufferedInputStream = new BufferedInputStream(fileInputStream);
// read the file
bufferedInputStream.read(mybytearray, 0, mybytearray.length);
outputStream = client.getOutputStream();
// write file to the output stream byte by byte
outputStream.write(mybytearray, 0, mybytearray.length);
outputStream.flush();
bufferedInputStream.close();
outputStream.close();
client.close();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Note: I do not want to use Google Cloud Print. 注意:我不想使用Google云打印。 Any help would be greatly appreciated.
任何帮助将不胜感激。 Thanks.
谢谢。
You might be able to use lpdspooler http://lpdspooler.sourceforge.net/ , that is, if the printer supports LPR/LPD. 您也许可以使用lpdspooler http://lpdspooler.sourceforge.net/ ,即打印机是否支持LPR / LPD。 If you can give some more details about the environment (printer, etc).
如果您可以提供有关环境(打印机等)的更多详细信息。
You can't directly connect to a printer and print from Android, unless the printer is cloud enabled. 除非打印机已启用云,否则您无法直接连接到打印机并从Android打印。
However, you can add the printer to your Google Cloud Print account and print to it using the APIs available. 但是,您可以将打印机添加到您的Google Cloud Print帐户,然后使用可用的API进行打印。
Note though that the computer that the printer is attached to will need to be in for print jobs to be processed. 请注意,尽管打印机需要连接到该计算机,然后才能处理打印作业。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.