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

R Rinami Developer 3 years 7 months ago
120 0 0

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 calledprivate 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);    }
}

CONTACT
Can’t find what you’re looking for?