Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Revision as of 05:07, 24 July 2013 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Contactless Communication API (JSR 257)

From Wiki
Jump to: navigation, search
Article Metadata
Created: firt (14 Apr 2007)
Last edited: hamishwillee (24 Jul 2013)

Contactless Communication API (JSR 257) defines a Java ME optional package that allows developer to access contactless communication, bi-directional communication and accessing read-only information using differente technologies via short-range wireless means, such as RFID or barcodes, infrared light, or even Bluetooth, and presents such devices via a simple, homogeneous interface to Java applications.

RFID in Brief:

  • RFID (Radio Frequency IDentification) is a technology to carry information over short range by radio waves
  • 13.56 MHz frequency used in mobile devices
  • A tag (transponder) contains digital information in a microchip
  • A reader communicates with a tag
  • Two types of tags
  • Active tag has own power source and longer distance
  • Passive tag gets power from the incoming signal

NFC and NFC Forum

  • NFC (Near Field Communication) specifies simple wireless communication between close coupled devices
  • NFC enables
    • Establishing other types of wireless communication between devices
    • Compatibility with existing contactless smart cards
  • NFC Forum defines common protocols for basic links between NFC enabled devices* NFC Forum Data Exchange Format (NDEF)
    provides vendor independent structure for data

Visual Tags in Brief

  • Optically machine readable information on printed material, typically in the form of bar codes or data matrices
  • Widely used in product identification
  • Symbology defines the features of the visual tag
  • Used character set
  • Encoding and decoding rules
  • Data size
  • Error checking
  • Printing requirements
  • Over 200 known symbologies, only few widely used
  • UPC / EAN / JAN in article numbering

Use Cases for JSR 257

  • Read a URL to movie web page from a tag
  • Store personal shortcuts like phone numbers to a tag
  • Bluetooth or WLAN connection initiation in a multiplayer game with RFID communication* Set device access point settings from a tag
  • Field force on-the-job reporting using RFID tags* Data gathering from RFID tags to a server


Registering for Target Discovery

//Get DiscoveryManager instance and set TargetListener
//for NDEF_TAG target
DiscoveryManager dm = DiscoveryManager.getInstance();
try {
dm.addTargetListener(this, TargetType.NDEF_TAG);
} catch (ContactlessException ce) {
// handle exception

Registering for NDEF - Record Discovery

// Get DiscoveryManager instance and set TargetListener
// for NDEF_TAG and NFC_PEER targets
DiscoveryManager dm = DiscoveryManager.getInstance();
try {
NDEFRecordType recordType = new NDEFRecordType(NDEFRecordType.NFC_FORUM_RTD, "MyOwnType");
dm.addNDEFRecordListener(this, recordType);
} catch (. . .) {
// handle exception

Making a Connection to the Target

public void targetDetected(TargetProperties[] prop) {
// Select first target
TargetProperties target = prop[0];
try {
// NDEF_TAG target found
String url = target.getUrl();
// Open NDEFTagConnection to the target
conn = (NDEFTagConnection);
// Read data from the target
NDEFMessage message = conn.readNDEF();
NDEFRecord[] records = message.getRecords();
} catch (. . .) {}

Receive Read-Only Data from NDEF Tag

public class MyMIDlet extends MIDlet implements NDEFRecordListener {
public void recordDetected(NDEFMessage ndefMessage) {
NDEFRecord[] records = ndefMessage.getRecords();
for (int i=0; i<records.length; i++) {
// Handle data

Read Visual Tag Image

public void readVisualTag() {
try {
String[] images = SymbologyManager.getImageClasses();
// Open connection to visual tag
VisualTagConnection conn = (VisualTagConnection)"vtag://");
String data = conn.readVisualTag(getImage(), images[0], mySymbology);
// Handle data from the image
} catch (. . .) {
// handle exception

Generate Visual Tag Image

public void generateVisualTag() {
try {
// Get properties for symbology
ImageProperties properties = SymbologyManager.getImageProperties("code-39");
String imageClass = getImageClass();
VisualTagConnection conn = (VisualTagConnection)"vtag://");
// Generate visual tag image
Object vtagImage = conn.generateVisualTag("test", imageClass, properties);
. . .
} catch (. . .) {
// handle exception


  • JSR 257 offers communication to various contactless targets
  • Can be extended to cover future contactless targets
  • Provides general discovery mechanism
  • Eases tasks of the application developer
  • Supports MIDP push mechanism for automatic application launch for NDEF formatted data
  • Flexible design and minimal set of mandatory features
  • Allows implementations to support only RFID tags or visual tags or both

More Information

This page was last modified on 24 July 2013, at 05:07.
46 page views in the last 30 days.