Sorry about the red box, but we really need you to update your browser. Read this excellent article if you're wondering why we are no longer supporting this browser version. Go to Browse Happy for browser suggestions and how to update.

Near Field Communication

BlackBerry smartphones that come equipped with a Near Field Communication (NFC) transceiver enable an app to interact with smart tags, smart accessories, and other NFC-enabled smartphones. Smart tags typically contain small amounts of data that describe an object in the world, or refers to another data channel where a user can get more information.

For example, a Bluetooth speaker could have an embedded smart tag that contains Bluetooth pairing information. A media-player app that detects the smart tag could initiate pairing and then route the BlackBerry smartphone audio output to the Bluetooth speakers.

NFC technology is designed to transfer small amounts of data over a short distance. Here are a few examples of what you can use smart tags to do:

  • Provide a web address where a BlackBerry smartphone user can retrieve more information about an advertisement on a smart poster, such as a movie or a coupon
  • Provide pairing information for a Bluetooth accessory
  • Provide identification information for a smart dock

Data exchange using NFC

There are several ways to exchange data with other NFC-enabled smartphones. The following table summarizes the various technologies and example use cases that the NFC API enables.

Data exchange technology

Potential use case

Physical smart tags

Smart tags allow for easy identification of real-world objects and locations. The NFC API enables you to read and write smart tags.

Emulated smart tag

Emulating a smart tag allows you to use a BlackBerry smartphone as smart tag. This feature is useful for sharing information that changes infrequently, such as contact information or links to virtual resources.

For example, you can share the URL for your app with another BlackBerry smartphone user by emulating a smart tag. If your app is installed on a smartphone when you detect this tag, you can open your app.

Emulating a smart tag also allows you to interact with a smart tag reader.

Simple NDEF Exchange Protocol (SNEP)

When the BlackBerry smartphone detects a SNEP request it notifies the app that has registered interest in SNEP requests. When your app receives a notification, you can generate an NDEF message dynamically and push the message to another NFC-enabled smartphone.

Logical Link Layer Protocol ( NFC LLCP)

You can create peer-to-peer connections between NFC-enabled smartphones using the LLCP. Peer-to-peer connections enable unrestricted data exchange between two smartphones while they are in range for an NFC connection.

Bluetooth connection handover

Some Bluetooth smartphones have a smart tag that carries pairing information. When a BlackBerry smartphone detects a tag with Bluetooth pairing information, it attempts to make a connection. An app can register to receive notifications of Bluetooth connection events, and communicate with a service on another smartphone once the connection is complete.

Secure element

You can use the secure element on a BlackBerry smartphone or a SIM card to store sensitive information such as credit card data, identification, and physical access credentials.

Access to the secure element API is protected by NFCR and RESE signing keys. These special signing keys are available to developers who have a business arrangement with Research In Motion to offer NFC services, or developers who work on behalf of a carrier partner.

Contact your RIM business partner for more details.

Working with smart tags

The NFC feature on a BlackBerry smartphone is typically activated by a BlackBerry smartphone user when the user taps a smart tag. If you registered a listener that matches the configuration of the smart tag that the user taps, the smartphone can notify your app that a tag is available.

You can implement the net.rim.device.api.io.nfc.ndef.NDEFMessageListener interface to receive messages from a smart tag that is configured according to the NDEF Technical Specification. The BlackBerry smartphone provides an NDEFMessage object that contains the data from the smart tag to an NDEFMessageListener. apps that register an NDEFMessageListener object can restrict the Record Type Definition and record type that trigger the app.

You can implement the net.rim.device.api.io.nfc.readerwriter.DetectionListener interface to enable your app to receive notification of a connection to any smart tag that conforms to the ISO14443 standard. When invoked, a DetectionListener receives a Target object that contains the URI that is required to open a connection to the tag.

When a smart tag is detected, the smartphone notifies any apps that registered a listener for that type of tag. Only one DetectionListener object can access a smart tag at a time while the smart tag is within the range of the NFC transceiver. When one DetectionListener finishes with the smart tag, another DetectionListener can open a connection to the smart tag if it is still in range.

Supported smart tags in BlackBerry 7.1

NFC Forum tag type

Supported tags

Type 1

  • Topaz 96
  • Topaz 512

Type 2

  • MiFare Ultra Light
  • MiFare Ultra Light C
  • Infineon my-D Move
  • Infineon my-D NFC

Type 3

FeliCa RC-S965

Type 4

MiFare DESFire EV1 (2k, 4k, 8k)

You can also communicate with smart tags using lower level protocols, such as ISO14443-3 and ISO 14443-4. For more information about communicating with smart tags using lower level protocols, see the API reference for the and the manufacturer's documentation for the tag.

The MiFare Classic 1k and 4k tags are not supported due to licensing constraints of some of the algorithms used by these tags.

NDEF Helper Classes

The net.rim.device.api.io.nfc.ndef.rtd package contains classes that can help you parse and create well-formed NDEF records. You can create SmartPosterRecord, TextRecord, and URIRecord objects from the payload of an NDEF message that you retrieve from a smart tag.

The following code snippet retrieves the URI from smart poster data and displays it in a label:

import net.rim.device.api.io.nfc.ndef.rtd.SmartPosterRecord;
import net.rim.device.api.io.nfc.ndef.*;
import net.rim.device.api.ui.UiApplication.

public void onNDEFMessageDetected(final NDEFMessage msg)
{
    UiApplication.getApplication().invokeLater(new Runnable()
    {
        public void run()
        {
            NDEFRecord[] records = msg.getRecords();
            SmartPosterRecord sp = new SmartPosterRecord(records[0]);
            lbl.setText(sp.getUri());
        }
    });   
}

The RTD helper classes also provide methods to help you wrap your data in common NDEF record types, such as smart poster, Text, and URI. You can add the objects you create to an NDEF message.

The following code snippet shows how to create an NDEF message that contains a single record with a text Record Type Definition:

import net.rim.device.api.io.nfc.ndef.rtd.TextRecord;
import net.rim.device.api.io.nfc.ndef.NDEFMessage;

NDEFRecord myRecord = new TextRecord("This is some text", "en-US");
NDEFMessage myMessage = new NDEFMessage();
myMessage.appendRecord(myRecord);

The net.rim.device.api.io.nfc.ndef.NDEFMessageUtils class contains methods to create fully formed NDEF messages that include the data you provide.

The following code snippet also creates an NDEF message with a single text record, but uses the NDEFMessageUtils class to create the message:

import net.rim.device.api.io.nfc.ndef.NDEFMessage;
import net.rim.device.api.io.nfc.ndef.NDEFMessageUtils;

NDEFMessage myMessage = NDEFMessageUtils.createTextNDEFMesssage(
                        "This is some text","en-US");