0 Replies Latest reply on Sep 5, 2017 12:45 AM by Rinami Developer

    BluetoothConnection.open() failure causes unpairing in Android with ZD420 printer

    Rinami Developer

      We are printing to ZD420 printers through an Android application. Prior to printing we check the status of any paired printers. If the printer is either offline or out of range we get a connection exception with the message "Could not connect to device: read failed, socket might closed or timeout, read ret: -1" when we call BluetoothConnection.open() which is expected. However, shortly after this exception is thrown, the Android device unpairs itself from the printer. This means that when the user comes back into range they must first pair the printer prior to being able to use it. How do we prevent the printer from being unpaired when attempting to open a connection?

       

      We are using version 2.11.2800 of the Android SDK

       

      Relevant code:

      private ZebraPrinterStatus getPrinterStatus(final String macAddress) {

          final Connection connection = new BluetoothConnection(macAddress);

          try {

              connection.open(); This is causing the exception and ultimately the unpair

              PrinterStatus status = getPrinterStatus(connection);
              connection.close();
              return new ZebraPrinterStatus(status);
          } catch (Exception e) {

              Log.e(TAG, "Failed to get zebra printer status", e);
          }

          return new ZebraPrinterStatus();
      }

       

      // assumes connection.open() has already been called
      private PrinterStatus getPrinterStatus(Connection connection) throws Exception {

          try {

              ZebraPrinter printer = ZebraPrinterFactory.getInstance(connection);
              return printer.getCurrentStatus();
          } catch (ConnectionException | ZebraPrinterLanguageUnknownException e) {

              throw new Exception("Cannot connect to printer", e);
          }

      }