【问题标题】:How to print data from Android app to WIFI printer?如何将数据从 Android 应用程序打印到 WIFI 打印机?
【发布时间】:2012-07-04 22:48:39
【问题描述】:

我正在 Android 2.1 中开发购物车应用程序。我想在用户提交订单时打印订单详情(客户详情、购物车详情、订单总额)。我想使用一些 WIFI 打印机来打印数据。请帮我举出合适的例子...

【问题讨论】:

  • 。请告诉我使用 Android 应用程序中的 WIFI 打印机打印的任何想法...
  • 如何以编程方式将 pdf 文件从 android 发送到 wifi 打印机?
  • 你得到解决方案了吗@Anoop

标签: android printing android-wifi


【解决方案1】:

我假设您想在收据大小的纸张上打印。如果是这样,Star Micronics 有一个 Android SDK,支持 Wifi 连接以及 USB 和蓝牙。在这里下载:http://starmicronics.com/support/sdkdocumentation.aspx

如果您正在寻找普通尺寸的打印机,请查看 Google 云打印:https://developers.google.com/cloud-print/?hl=en

【讨论】:

  • 您好,谢谢,但是您知道此 SDK 是仅适用于 Star 打印机还是适用于其他品牌的打印机?我正在尝试通过该 SDK 连接我的打印机,这对我来说似乎是不可能的
【解决方案2】:

从 ip 地址和端口号创建一个 Socket 连接。

 String ip = "your printer ip address";
 int port = port number; 

private class printTCP extends AsyncTask<String, Void, String> {
    
            @Override
            protected String doInBackground(String... params) {
              
                if (!ip.equals("")) {
                    if ((pref.getString(Const.PORT_CASH) != null) && (!pref.getString(Const.PORT_CASH).equals(""))) {
                        port = Integer.parseInt(pref.getString(Const.PORT_CASH));
                        try {
                            client = new Socket(ip, port);// ip address and port number of ur hardware device
                            String text = "Test Print";
                            byte[] bytes = text.getBytes(); //create a byte array 
                           
                            outputStream = client.getOutputStream();
    
                            outputStream.write(bytes, 0, bytes.length); //write file to the output stream byte by byte
                            outputStream.flush();
                            outputStream.close();
                            client.close();
    
                        } catch (UnknownHostException e) {
                            e.printStackTrace();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }
    
                return null;
            }
    
            @Override
            protected void onPostExecute(String result) {
    
            }
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 2017-07-30
    相关资源
    最近更新 更多