First need a jar package, BLUESDK, please own Baidu.
The specific layout style is the same as the network printer print layout style implementation, here is not much to describe, only one implementation method code. Bluetooth printer needs to be paired with the phone before use, can be saved locally, record the address, here you can see me every time I call this method to let the thread rest 1s, because the test found that when the data volume is particularly large, repeated calls to this method will result in the loss of data, so, each execution is completed, Let him rest for 1s minutes.
Public voidprintdata (String data) {if(Settings.BluetoothDeviceAddress.equals ("") {Mytoast.mylogo (history). This, "Print error, please check the printer or retry"); 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, "Print error, please check the printer or retry"); } Else{Settings.BluetoothManager.PrintData (data); } } Catch(Exception e) {Mytoast.mylogo (history). This, "Print error, please check the printer or retry"); E.printstacktrace (); Try{Settings.BluetoothManager.shutdownServer (); Settings.BluetoothManager.ConnectServer (); Settings.BluetoothManager.PrintData (data); } Catch(IOException E1) {Mytoast.mylogo (history). This, "Print error, please check the printer or retry"); E1.printstacktrace (); return; } } Try { //rest 1s after each printThread.Sleep (1000); } Catch(interruptedexception e) {//TODO auto-generated Catch blockE.printstacktrace (); } }
Android calls a Bluetooth printer