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 09:30, 11 June 2009 by tanjaluodes (Talk | contribs)

How to read serial number of NDEF (NFC) tag

From Wiki
Jump to: navigation, search

Near Field Communication (NFC) is a short-range wireless connectivity technology that offers simple, intuitive, and safe communication between electronic devices. Nokia is active in the area of NFC, and the company launched the world’s first fully integrated NFC phone in January 2007. This simple MIDlet can be used to read the serial number of an NDEF tag.

import javax.microedition.contactless.ContactlessException;
import javax.microedition.contactless.DiscoveryManager;
import javax.microedition.contactless.TargetListener;
import javax.microedition.contactless.TargetProperties;
import javax.microedition.contactless.TargetType;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
// Simple MIDlet to read the serial number of NDEF tag
public class ReadSerial extends MIDlet implements TargetListener {
private Form form;
private TextField textField;
protected void startApp() throws MIDletStateChangeException {
// Get instance of NFC Discovery Manager
DiscoveryManager dm = DiscoveryManager.getInstance();
// Register NDEF_TAG target to discovery
try {
dm.addTargetListener(this, TargetType.NDEF_TAG);
} catch (IllegalStateException e) {
// Catch IllegalStateException
} catch (ContactlessException e) {
// Catch ContactlessException
// Initialize and show user interface elements
form = new Form("ReadSerial");
textField = new TextField("Unique identifier:", "", 255, TextField.UNEDITABLE);
protected void pauseApp() {
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
public void targetDetected(TargetProperties[] prop) {
// Set unique identifier of the detected target on the Text Field
68 page views in the last 30 days.