从Android应用程序使用蓝牙打印机打印数据 [英] Print data from android app using bluetooth printer
问题描述
我开发了餐厅一个Android应用程序。我想从我的应用程序订购后打印账单。我使用蓝牙打印机进行打印任务。使用蓝牙打印机具有打印数据遇到任何的身体,请帮助一些适当的例子。
I am developing an android app for restaurant . I want to print the bill after ordering from my app . I am using Bluetooth printer for the printing task . Any body having experience in printing data using Bluetooth printer ,please help with some suitable examples .
推荐答案
是的,我有相同的应用经验。你需要使用的StreamConnection
类与的InputStream
和的OutputStream
类。
Yes, I have experience of same application. You need to use StreamConnection
class with the InputStream
and OutputStream
class.
首先,你需要使用它的蓝牙地址,以与蓝牙打印机连接,然后你需要发送的字符使用的OutputStream
类打印。
First you need to make connection with Bluetooth Printer using its Bluetooth Address and then you need to send characters to print using OutputStream
class.
在打印机端时,将取回的字符会直接开始打印。
On the printer side when it will fetch the characters it will directly start printing it.
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 ) { }
}
这篇关于从Android应用程序使用蓝牙打印机打印数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!