Testing NFC apps

BlackBerry devices that support near field communication (NFC) can read a smart tag, a smart accessory, or another NFC-enabled device. NFC technology is designed to transfer small amounts of data over a short distance. For example, you could provide pairing information for a Bluetooth accessory. You can create NFC tags, populate them with data, and present them to the simulated device. The default tag type is Blank, which means that the tag has no information and is writable by the device. You can also use Text, URI, or Smart Poster tags to perform the following tasks:

  • Provide a URL where a 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.

Create a new NFC tag

  1. In the controller, click NFC.
  2. Choose an NFC tag type and enter the required information.
  3. If you want your app to be able to write to the tag, select the Writable check box.


Screen showing simulator's NFC controls.

Simulate tapping an NFC tag on a device

  1. In the controller, in the NFC dialog box, select your tag.
  2. Click Present.
  3. To simulate moving the tag away from the simulator, click Remove.

Simulate a P2P NFC connection

  1. Ensure that you have two simulators running.
  2. In the controller, click NFC.
  3. Enter the IP Address of the simulator you wish to connect to and click Connect P2P.
  4. To disconnect, click NFC > Disconnect.


Screen showing simulator's NFC peer-to-peer connection controls.

Near Field Communication (NFC) support

NFC defines standards for smartphones to establish two-way radio communication for transmitting a small amount of information over a short distance, such as an inch or two. For example, you can use NFC for monetary transactions, data exchange, and a simplified setup of more complex communications, such as Wi-Fi.

NFC requires a provider and a target. The provider generates an RF field that can power a passive target. There are two ways to configure NFC:
  • Passive communication

    The provider device creates an RF carrier field and the target device answers by modulating the existing field. In this mode, the target device draws operating power from the provider's field, such as between a smartphone and an unpowered NFC tag. Tags may be read-only or read-writable. The simulator can emulate a target as described in the NFC tag emulation mode and NFC smart poster mode sections below.

  • Active communication

    Two devices can communicate as peers, as described in the NFC P2P support section below, by running two simulators concurrently. Each simulator alternates between acting as a provider (generating its own transmitting field) and a target (deactivating its field while listening).

There are three simulation components in the simulator:
  • Simulation provider

    SimNFCProvider simulates OpenNFCProvider and the device driver. It implements NFC Provider APIs, and communicates with the other two NFC components in the same way as OpenNFCProvider.

  • NFC simulation GUI

    The GUI provides a means to simulate a peer device in an NFC simulation:

    • When simulating a tag reader/writer on the device, the GUI acts as a tag.

    • When simulating tag emulation on the device, the GUI acts as a tag reader/writer.

    The NFC simulation GUI also allows you to control and configure NFC simulation.

  • Simulation connector

    The connector simulates the NFC connection and events between the device and its peer in NFC simulation. For tag reader/writer and tag emulation, it connects the simulator with the GUI. For peer-to-peer simulation, it connects two simulators to each other.

NFC smart poster support

NFC smart posters are similar to QR codes. Users can receive additional information directly to their smartphone. The following describes the passive communication simulator's smart poster tag implementation:

You can access these commands from the controller using the NFC menu.

  1. To present a smart poster tag:

    • In the NFC controller, choose Smart Poster from the drop-down list. When Smart Poster is selected, you are prompted for a URI (mandatory), Title (optional), and Action (optional).

      The following are possible values for Action:
      • No action
      • Launch the browser
      • Save for later (for example, bookmark a URI)
      • Edit for editing (for example, open the URI in a URI editor)
  2. To receive a smart poster tag in write command.

    This is handled in a manner similar to that of a virtual text tag, the difference is that a smart poster may contain URI, text (Title) and Action.

  3. To receive a virtual smart poster tag (emulation mode).

    This is handled in a similar manner as a virtual text tag. The difference is that a virtual smart poster tag may contain URI, text (Title) and Action.

NFC tag emulation

Emulating an NFC tag is similar to the tag read/write emulation. You need to run the simulator and the controller. To test emulation, you must run an application on the simulator that emulates the virtual tag, and set the controller to listening mode.  To set up the controller, click NFC > Listen for virtual tag.

To run the Tap2Test application on the simulator:
  1. Select Emulate tag.
  2. Append a record (this creates the message for the virtual tag).
  3. Click Register.

The controller displays a dialog box that indicates a virtual tag is detected. You can now view the content of the tag.

To use a second NFC application on the simulator, run the application on the simulator, and set the controller to listening mode. When the application calls the appropriate APIs to register for a virtual tag (or for tag emulation), the tag appears on the controller.

NFC Peer-to-Peer (P2P) support

In P2P mode, two NFC devices can exchange data. When there is a small amount of data to be transferred between the devices (such as a URL), the data is transferred using the NFC SNEP protocol. When there is a large amount of data (such as a picture), typically a Bluetooth connection is established using NFC (also called connection handover), and then the data is transferred over the Bluetooth connection. Currently, the simulator supports only SNEP for P2P.

The major work in simulating P2P communication is managing connectivity between two simulators. Unlike other modes, the simulator is not involved in NDEF message constructing. Three levels of connections are involved in simulating P2P communication:
  1. A physical connection between two devices

  2. LLCP connection

  3. Connection between a SNEP client and SNEP server

Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus