Connection Management

RFID SDK for Android 2.0.1.15

Overview

This guide provides steps to perform various connection related task using RFID API3

Connect to an RFID Reader

Connection is the first step to talk to an RFID reader

  1. Import the package
  2. 
    import com.zebra.rfid.api3.*;
    
  3. Create instance of Readers class with passing activity context as first parameter and enum value SERVICE_SERIAL as second parameter
  4. 
    readers = new Readers(this, ENUM_TRANSPORT.SERVICE_SERIAL);
    
  5. The Readers class instance gives a list of all available/paired RFID readers with an Android device. Readers list is in the form of ReaderDevice class.
  6. 
    ArrayList readersListArray = readers.GetAvailableRFIDReaderList(); 
    ReaderDevice readerDevice = availableRFIDReaderList.get(0);
    
  7. ReaderDevice class includes instance of RFIDReader class; which is root class to interface and performing all operations with RFID reader.
  8. 
    // Establish connection to the RFID Reader
    rfidReader.connect();
    

Special Connection Handling Cases

In a normal scenario, the reader connects fine, but the following are the cases which require special handling at the time of connection. The following example demonstrates the connection is handled under try-catch block and OperationFailure exception is thrown by connection API is stored and used for further analysis


private OperationFailureException ex; 
try { 
    // Establish connection to the RFID Reader 
    rfidReader.connect(); 
} 
catch (InvalidUsageException e) 
{ 
    e.printStackTrace(); 
} 
catch (OperationFailureException e) 
{   
   e.printStackTrace(); 
   ex = e; 
}

Disconnect

When the application is done with the connection and operations on the RFID reader, it calls the following API to close the connection, and to release and clean up the resources.


// Disconnects reader and performs clean-up 
rfidReader.disconnect();
NOTE: If a reader disconnection occurs, the reader.isConnected() flag may return the value false. If application has called the reader.connect() then application should call reader.disconnect() regardless of the flag status

Dispose

When the application main activity is destroyed, it is required to dispose the SDK instance so that it can cleanly exit (unregistration and unbind by SDK as required).


readers.Dispose();