简体   繁体   English

将android设备与打印机连接并打印文档

[英]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.

相关问题 将Android设备连接到WiFi打印机以编程方式进行打印 - Connect Android device to WiFi printer to take print programatically 使用打印机管理器将wifi打印机连接到android设备以编程方式打印PDF - Connect wifi Printer to android device to take PDF print programatically using Printer Manager 将 Android 设备连接到 WiFi 打印机 - Connect Android device to WiFi printer 想要将我的Android设备(手机/平板电脑)连接到打印机以进行应用程序打印 - Want to connect my Android device (mobile / tablet) to Printer for application print purpose 如何使用共享打印机从安卓设备打印? - How to print from android device with shared printer? 如何从Android设备连接到wifi打印机? - how to connect to wifi printer from android device? 如何从android设备打印到windows网络共享打印机? - How print from android device to windows network shared printer? Xamarin:如何从Android设备打印到点矩阵打印机? - Xamarin: How to print from Android device to dot matrix printer? 如何通过无线连接将epson打印机连接到Android设备 - How to connect epson printer to android device via wireless connection 是否可以在没有互联网连接的情况下将android设备连接到打印机? - Is it possible to connect android device to a printer without internet connection?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM