Use Contactless CPU Card
Last updated
Last updated
This section provides a step-by-step guide on using the Java API for interacting with contactless CPU cards.
Get RFCardReaderDevice:
Retrieve the instance of the RFCardReaderDevice to initiate communication with the contactless card reader.
device = (RFCardReaderDevice) POSTerminal.getInstance(mContext).getDevice(POSTerminal.DEVICE_NAME_RF_CARD_READER);
Open Device:
Execute the command to open the card reader device. This step establishes a connection between the Java application and the card reader.
device.open();
Search for Card:
Initiate a search for the contactless CPU card. This involves scanning for available cards within the reader's range.
OperationListener listener = new OperationListener() {
@Override
public void handleResult(OperationResult arg0) {
if (arg0.getResultCode() == OperationResult.
Communicate with Card:
Once the card is detected, establish communication. This step may involve reading from or writing to the card, depending on the application's requirements.
if (rfCard instanceof CPUCard) {
CPUCard cpucard = ((CPUCard) rfCard);
ATR atr = cpucard .connect();
result = cpucard .transmit(arryAPDU);
cpucard .disconnect();
}
Close Device:
After the communication with the card is complete, close the device to end the session. This step is crucial for maintaining device security and integrity.
device.close();