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 .
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Yes, I have experience of same application. You need to use StreamConnection
class with the InputStream
and OutputStream
class.
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 ) { }
}