Android调用蓝牙打印机
生活随笔
收集整理的這篇文章主要介紹了
Android调用蓝牙打印机
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
首先需要一個jar包,bluesdk,請自行百度。
具體排版樣式跟網絡打印機打印排版樣式實現一樣,這里不多敘述,只貼一個實現方法代碼。藍牙打印機使用前需要先跟手機配對,可以保存在本地,記錄下地址,這里可以看到我每次調用這個方法 讓線程休息了1s,原因是通過測試發現,當數據量特別大的時候,反復調用這個方法會出現丟失數據的現象,所以,每次執行完畢,都讓他休息1s鐘。
public void printData(String data) {if (Settings.BluetoothDeviceAddress.equals("")) {MyToast.MyLogo(History.this, "打印錯誤,請檢查打印機或重試");return;}System.out.println("Settings.BluetoothDeviceAddress:" + Settings.BluetoothDeviceAddress);try {Settings.BluetoothManager.setServerAddress(Settings.BluetoothDeviceAddress);if (!Settings.BluetoothManager.IsConnected()) Settings.BluetoothManager.ConnectServer();if (!Settings.BluetoothManager.IsConnected()) {MyToast.MyLogo(History.this, "打印錯誤,請檢查打印機或重試");} else {Settings.BluetoothManager.PrintData(data);}} catch (Exception e) {MyToast.MyLogo(History.this, "打印錯誤,請檢查打印機或重試");e.printStackTrace();try {Settings.BluetoothManager.shutdownServer();Settings.BluetoothManager.ConnectServer();Settings.BluetoothManager.PrintData(data);} catch (IOException e1) {MyToast.MyLogo(History.this, "打印錯誤,請檢查打印機或重試");e1.printStackTrace();return;}}try {// 每次打印后休息1sThread.sleep(1000);} catch (InterruptedException e) {// TODO Auto-generated catch block e.printStackTrace();}}?
轉載于:https://www.cnblogs.com/LIANQQ/p/4587650.html
總結
以上是生活随笔為你收集整理的Android调用蓝牙打印机的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Spark1.3.0安装
- 下一篇: js定时器、高亮修改单元格背景色