【问题标题】:Print data from android app using bluetooth printer使用蓝牙打印机从安卓应用打印数据
【发布时间】:2012-08-17 09:40:55
【问题描述】:

我正在为餐厅开发一个安卓应用。我想从我的应用程序订购后打印账单。我正在使用蓝牙打印机进行打印任务。任何有使用蓝牙打印机打印数据经验的人,请提供一些合适的例子。

【问题讨论】:

    标签: android printing bluetooth


    【解决方案1】:

    是的,我有相同应用的经验。您需要将StreamConnection 类与InputStream 和OutputStream 类一起使用。

    首先您需要使用蓝牙地址与蓝牙打印机建立连接,然后您需要使用OutputStream 类发送字符进行打印。

    在打印机端,当它获取字符时,它会直接开始打印。

    private StreamConnection bConn = null; 
    private DataOutputStream dos = null; 
    
     try
     {
        bConn = (StreamConnection) Connector.open(PrinterURL);
        dos = (DataOutputStream)bConn.openDataOutputStream();
        dos.writeUTF("\r\n");
        dos.writeUTF("===============================");dos.writeUTF("\r\n");
        dos.writeUTF("          GSECL Bill"); dos.writeUTF("\r\n");
        dos.writeUTF("===============================");dos.writeUTF("\r\n");
      }
      catch ( Exception e ) { System.out.println "Server Error: " + e.toString() );
    
    finally
    {
        try
            { 
            dos.close();
        bConn.close();
        }
        catch ( Exception e ) { }
        }
    

    【讨论】:

    • 如何获取蓝牙打印机的蓝牙地址。
    • 创建一个检测蓝牙设备的示例项目,你可以从中找到它:)
    • 当然,我建议你提出一个新问题,这样对其他人也有帮助。
    • @KinjalShah,J2ME中用于制作HttpConection/StreamConnectoin的Connector类,可以在google.com上搜索其描述
    • @KinjalShah 当然,做一件事,用您的代码和错误代码(如果有的话)提出一个新的新问题,这样您也可能会得到其他开发人员的更多回应 :)跨度>
    猜你喜欢
    • 1970-01-01
    • 2012-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多