Package javax.microedition.contactless.ndef

Provides functionality to exchange NDEF formatted data with other contactless targets.

See:
          Description

Interface Summary
NDEFRecordListener The NDEFRecordListener provides a mechanism for the application to be notified, when NDEF records are discovered from the contactless targets.
NDEFTagConnection The NDEFTagConnection interface defines the basic functionality for exchanging NFC Forum formatted data with RFID tags and contactless smart cards.
 

Class Summary
NDEFMessage This class represents an NDEF message.
NDEFRecord This class represents an NDEF record.
NDEFRecordType This class encapsulates the type of an NDEF record.
 

Package javax.microedition.contactless.ndef Description

Provides functionality to exchange NDEF formatted data with other contactless targets.

Package Specification

The NFC Forum specifies a data packaging format to exchange information between an NFC device and another NFC device or a tag. The data formatting is based on NDEF records that contain type, type format, identifier and the actual data. This API takes advantage of this data formatting by providing a connection to any physical target that supports NDEF data formatting defined by the NFC Forum. Using this data format, the application developer does not have to know the physical type of the target to exchange NDEF messages with it. This package provides means to generate and manipulate NDEF messages and NDEF records.

Applications can request a notification when the discovered target contains a specified NDEF record type. This is done by setting an NDEFRecordListener with DiscoveryManager.addNDEFRecordListener method. When a target containing the requested NDEF record type is detected, a notification is sent to the registered application(s). The data from the target is provided to the application(s) in the notification.

This API supports the possibility to request application startup based on the data on the target appearing to the proximity of the device. The application startup is supported for the NDEF record types and for the secure element activity in card emulation mode. For more information see Appendix B: Launching applications with MIDP 2.0 PushRegistry.

The following code example shows how to read data from an NDEF_TAG target.

import java.io.IOException;
import javax.microedition.contactless.*;
import javax.microedition.contactless.ndef.*;
import javax.microedition.io.Connector;

/**
 * Example class of how to read data from NDEF_TAG target
 * using JSR 257 Contactless Communication API
 */
public class CCAPIExample implements TargetListener {

    private NDEFTagConnection conn = null;

    public CCAPIExample() {
        registerTargetToDiscovery();
    }
 
    public void registerTargetToDiscovery() {
        // do the target discovery registration
    }
    
    public void targetDetected(TargetProperties[] prop) {

        // Select first found target
        TargetProperties target = prop[0];
        // check that target type is NDEF_TAG
        TargetType[] types = target.getTargetTypes();
        for (int i=0; i<types.length; i++) {
            if (types[i].equals(TargetType.NDEF_TAG)) {
                try {
                    // Get URL to open the connection
                    String url = target.getUrl();
                    // Open NDEFTagConnection to the target
                    conn = (NDEFTagConnection)Connector.open(url);
                    // Read data from the target
                    NDEFMessage message = conn.readNDEF();
                    NDEFRecord[] records = message.getRecords();
                    for (int j=0; j<records.length; j++) {
                        // Handle data
                    }
                }
                catch (IOException ioe) {
                    // Handle exception
                }
                catch (ContactlessException ce) {
                    // Handle exception
                }
            }
            else {
                i++;
            }
        }
    }
                
}
        



Copyright © 2005-2006 Nokia Corporation. All Rights Reserved.
Java is a trademark of Sun Microsystems, Inc.