Android calls a Bluetooth printer

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.