Android 中的 wifi 打印

发布于 2024-12-14 06:03:47 字数 688 浏览 6 评论 0原文

我想在我的 Android 应用程序中使用 wifi 打印来打印文件。我已经扫描了 wifi 打印机,并且我有 wifi 打印机 IP 地址。现在我如何将文件从 Android 手机传输到打印机进行打印?我正在使用以下代码将文件传输到打印机 `public void uploadFile(File fileName){

     FTPClient client = new FTPClient();
    try {
        client.connect(FTP_HOST,21);
        client.login(FTP_USER, FTP_PASS);
        client.setType(FTPClient.TYPE_BINARY);
        client.changeDirectory("/");
        client.upload(fileName, new MyTransferListener());
    } catch (Exception e) {
        e.printStackTrace();
        try {
            client.disconnect(true);    
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }

}`

有人可以帮助我吗?提前致谢。

I want to print file using wifi printing in my android application.I have scanned wifi printer and i am having wifi printer IP address . Now how can i transfer file from android phone to printer to print it ? I am using following code to transfer file to printer `public void uploadFile(File fileName){

     FTPClient client = new FTPClient();
    try {
        client.connect(FTP_HOST,21);
        client.login(FTP_USER, FTP_PASS);
        client.setType(FTPClient.TYPE_BINARY);
        client.changeDirectory("/");
        client.upload(fileName, new MyTransferListener());
    } catch (Exception e) {
        e.printStackTrace();
        try {
            client.disconnect(true);    
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }

}`

Can anybody help me ? Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伤感在游骋 2024-12-21 06:03:47

使用 Socket,您可以在 WIFI 连接中使用网络打印机从 Android 进行打印

Socket objSocket = new Socket();
String sIP = "192.168.1.10"
String sPort = "9100"
InetSocketAddress objEndPoint = new InetSocketAddress(sIP, Integer.parseInt(sPort));

DataOutputStream objOutputStream;

objSocket.connect(objEndPoint, 3000);

objOutputStream = new DataOutputStream(objSocket.getOutputStream());
objOutputStream.write(("Test Print").getBytes());

objOutputStream.close();
objSocket.close();

Using Socket you can print from android using network printer in WIFI Connection

Socket objSocket = new Socket();
String sIP = "192.168.1.10"
String sPort = "9100"
InetSocketAddress objEndPoint = new InetSocketAddress(sIP, Integer.parseInt(sPort));

DataOutputStream objOutputStream;

objSocket.connect(objEndPoint, 3000);

objOutputStream = new DataOutputStream(objSocket.getOutputStream());
objOutputStream.write(("Test Print").getBytes());

objOutputStream.close();
objSocket.close();
伪装你 2024-12-21 06:03:47

我认为你可以在不发送整个文件的情况下做到这一点,只需从文件中选择字符串并与 wifi 设备建立连接,将文本发送到设备,它就会打印它。我对蓝牙打印机做了同样的事情。

I think you can might do it without sending whole file, just pick the Strings from the file and make connection with the wifi device, send the text to the device, it will print it. I have done same thing with the bluetooth printer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文