How to give print command to printer from Android app?

狂风中的少年 提交于 2019-11-30 09:36:10

问题


I have created a simple app in which I give print command to printer but nothing happens.

Here is my code:

new Thread(new Runnable() {

    @Override
    public void run() {
        // TODO Auto-generated method stub
        Socket socket;
        try {
            socket = new Socket("xxx.xxx.xx.21", 515);
            PrintWriter outputStream = new PrintWriter(socket.getOutputStream());
            outputStream.println("\fThis is a test print");
            outputStream.close();
            socket.close();
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}).start();

When I run this code it works but doesn't print anything on printer.

Configuration details:

I have my laptop, android device & printer in same network. I tested IP addresses of all the 3 as well as port number of printer. Also, I pinged to printer's IP address from my laptop command prompt so I get reply but when I connect through device nothing happens.

来源:https://stackoverflow.com/questions/29094911/how-to-give-print-command-to-printer-from-android-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!