0 Replies Latest reply on Mar 17, 2016 2:27 PM by harry izquierdo

    Second printing problem bluetooth

    harry izquierdo

      Please help.

      I'm a developer, I have a problem when printing for the first time the Zebra MZ 220 does so without any problem, but when printed again not, it's as if I lost the Bluetooth connection, I read that I need to implement the class "ConnectionReestablisher "but I can not find examples anywhere, I need help. I'm testing a tablet Android.

       

      The steps are made:
      1. add the permissions in the "AndroidManifest.xml" file

           <Uses-permission android: name = "android.permission.BLUETOOTH" />      <Uses-permission android: name = "android.permission.BLUETOOTH_ADMIN" /> 

      2. create the class Printer.java

       public class Printer { String macAddressPrinter = "0022583CBA92"; private Connection connection; private ZebraPrinter printer;  public Printer(){}   public boolean open(){ connection = new BluetoothConnection(macAddressPrinter); try { connection.open(); return true; } catch (ConnectionException e) { e.printStackTrace(); return false; } }  public boolean close(){ try { if (connection != null) { connection.close(); } return true; } catch (ConnectionException e) { e.printStackTrace(); return false; } }  public void print(){ try { printer = ZebraPrinterFactory.getInstance(connection); PrinterLanguage printerLanguage = printer.getPrinterControlLanguage(); connection.write("harry! 0 200 200 200 1 ENCODING UTF-8 TEXT 0 20 30 r/n/ PRINTr/n/".getBytes()); Thread.sleep(1000); if (connection instanceof BluetoothConnection) { String friendlyName = ((BluetoothConnection) connection).getFriendlyName(); Thread.sleep(1000); System.out.print(friendlyName); } } catch (ConnectionException e) { e.printStackTrace(); } catch (ZebraPrinterLanguageUnknownException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } }   

      3.- Call the class where needed

      Printer obj = new Printer(); obj.open(); obj.print(); obj.close(); 

       

       

      Second printing MZ 220 · Issue #3 · developer-zebra/developer-zebra-site · GitHub