【发布时间】:2012-08-17 09:40:55
【问题描述】:
我正在为餐厅开发一个安卓应用。我想从我的应用程序订购后打印账单。我正在使用蓝牙打印机进行打印任务。任何有使用蓝牙打印机打印数据经验的人,请提供一些合适的例子。
【问题讨论】:
标签: android printing bluetooth
我正在为餐厅开发一个安卓应用。我想从我的应用程序订购后打印账单。我正在使用蓝牙打印机进行打印任务。任何有使用蓝牙打印机打印数据经验的人,请提供一些合适的例子。
【问题讨论】:
标签: android printing bluetooth
是的,我有相同应用的经验。您需要将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 ) { }
}
【讨论】: