NFC contactless

Guest post by Martin Woolley

Today’s post is the fourth part of a si- part series on porting BlackBerry Java applications that use NFC to BlackBerry 10. So far, we’ve looked at Tag Reading, Tag Writing and Peer to Peer mode. This time, we’ll review the porting of code that deals with reading contactless NFC cards such as transportation tickets.

Here’s where we are in the series as a whole:

  1. Reading NFC Tags
  2. Writing NFC Tags
  3. Peer to Peer Mode
  4. Reading NFC Contactless Cards
  5. NFC Virtual Tag and Card Emulation
  6. NFC Card Emulation

Reading NFC Contactless Cards – Issues for Java Developers:

  1. Detecting the card: The application must implement the DetectionListener interface and register it with ReaderWriterManager.addDetectionListener(…). When a card comes into proximity with the device, there will be a callback to the DetectionListener.
  1. Exchange ISO7816-4 APDUs with the card: We then obtain an ISO14443Part4Connection object associated with the Target provided in the callback to the DetectionListener and use the connection object’s transceive method to exchange ISO7816-4 APDUs in byte array format.

The BlackBerry 10 Native approach:

We use BPS (BlackBerry Platform Services) to detect and then exchange ISO7816-4 APDUs with the card.

Detecting the card (“target”) is the same as for writing a tag and is explained elsewhere in this guide.  Exchanging APDUs with the card is shown in the following code fragment which formulates and exchanges a SELECT command with the card:

Hopefully this was helpful and will make your porting work nice and easy!

Resources

Sample Code:

Contacts:

image

Excerpt from:  

Porting BlackBerry Java NFC Applications to BlackBerry 10 Part 4: Reading a Contactless Card