How to Understand Java API Usage for Felica Cards: Difference between revisions

From wizarPOS
No edit summary
No edit summary
Line 1: Line 1:
* Get RFCardReaderDevice
== Overview ==
This section outlines the procedure for using Java API to interact with Felica cards, which differ from standard contactless CPU cards.
== Steps for Java API Usage with Felica Cards ==
* '''Get RFCardReaderDevice:'''
Initialize by obtaining an instance of the RFCardReaderDevice. This is the first step in establishing communication with the Felica card reader.
<syntaxhighlight lang="java" line='line'>
<syntaxhighlight lang="java" line='line'>
   device = (RFCardReaderDevice) POSTerminal.getInstance(mContext).getDevice(POSTerminal.DEVICE_NAME_RF_CARD_READER);
   device = (RFCardReaderDevice) POSTerminal.getInstance(mContext).getDevice(POSTerminal.DEVICE_NAME_RF_CARD_READER);
</syntaxhighlight>
</syntaxhighlight>
* Open device
* '''Open Device:'''
Execute the command to open the card reader device. This action establishes a connection between your Java application and the card reader.
<syntaxhighlight lang="java" line='line'>
<syntaxhighlight lang="java" line='line'>
   device.open();
   device.open();
</syntaxhighlight>
</syntaxhighlight>
* Search Card
* '''Search for Card:'''
Conduct a search operation to detect the Felica card within the reader's range.
<syntaxhighlight lang="java" line='line'>
<syntaxhighlight lang="java" line='line'>
   OperationListener listener = new OperationListener() {
   OperationListener listener = new OperationListener() {
Line 22: Line 28:
   device.listenForCardPresent(listener, TimeConstants.FOREVER); The result will be returned in the callback listener.  
   device.listenForCardPresent(listener, TimeConstants.FOREVER); The result will be returned in the callback listener.  
</syntaxhighlight>
</syntaxhighlight>
* Communicate with Card
* '''Communicate with the Card:'''
Once the Felica card is identified, proceed to communicate with it.
<syntaxhighlight lang="java" line='line'>
<syntaxhighlight lang="java" line='line'>
   if (rfCard instanceof FelicaCard) {
   if (rfCard instanceof FelicaCard) {
Line 28: Line 35:
   }
   }
</syntaxhighlight>
</syntaxhighlight>
  Felica card is different with a normal contactless CPU card, its' APDU command is special, generally, it includes N(2 bytes,little endian) + CmdID (1 bytes) + data, please refer to the customer spec to get detail information for APDU command.
* '''Note on APDU Commands for Felica Cards:'''
* Close device
** Felica cards use a unique APDU command structure. Typically, this includes N (2 bytes in little-endian format), CmdID (1 byte), followed by data.
** Refer to the specific customer specifications for detailed information regarding the APDU commands for Felica cards.
* '''Close Device:'''
Conclude the session by closing the device. This step is essential for security and proper device management.
<syntaxhighlight lang="java" line='line'>
<syntaxhighlight lang="java" line='line'>
   device.close();
   device.close();
</syntaxhighlight>
</syntaxhighlight>
== Important Considerations ==
* The communication process with Felica cards requires adherence to their specific APDU command structure.
* Developers should consult detailed customer specifications for precise command formats and data handling.

Revision as of 20:15, 6 January 2024

Overview

This section outlines the procedure for using Java API to interact with Felica cards, which differ from standard contactless CPU cards.

Steps for Java API Usage with Felica Cards

  • Get RFCardReaderDevice:

Initialize by obtaining an instance of the RFCardReaderDevice. This is the first step in establishing communication with the Felica 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 action establishes a connection between your Java application and the card reader.

  device.open();
  • Search for Card:

Conduct a search operation to detect the Felica card within the reader's range.

  OperationListener listener = new OperationListener() {
    @Override
    public void handleResult(OperationResult arg0) {
      if (arg0.getResultCode() == OperationResult.SUCCESS) {
        sendSuccessLog2(mContext.getString(R.string.find_card_succeed));
        rfCard = ((RFCardReaderOperationResult) arg0).getCard();
      } else {
        sendFailedLog2(mContext.getString(R.string.find_card_failed));
      }
    }
  };
  device.listenForCardPresent(listener, TimeConstants.FOREVER); The result will be returned in the callback listener.
  • Communicate with the Card:

Once the Felica card is identified, proceed to communicate with it.

  if (rfCard instanceof FelicaCard) {
    result = ((FelicaCard) rfCard).transmit(arryAPDU, 0);
  }
  • Note on APDU Commands for Felica Cards:
    • Felica cards use a unique APDU command structure. Typically, this includes N (2 bytes in little-endian format), CmdID (1 byte), followed by data.
    • Refer to the specific customer specifications for detailed information regarding the APDU commands for Felica cards.
  • Close Device:

Conclude the session by closing the device. This step is essential for security and proper device management.

  device.close();

Important Considerations

  • The communication process with Felica cards requires adherence to their specific APDU command structure.
  • Developers should consult detailed customer specifications for precise command formats and data handling.