javax.microedition.contactless.ndef
Interface NDEFTagConnection

All Superinterfaces:
javax.microedition.io.Connection, TagConnection

public interface NDEFTagConnection
extends TagConnection

The NDEFTagConnection interface defines the basic functionality for exchanging NFC Forum formatted data with RFID tags and contactless smart cards. The actual data is stored in the NDEFMessage object containing the data in NDEF records.

This interface provides the means to read data from and write data to a target without knowing the actual physical type of the target. Each different target type that contains NFC Forum formatted data can be accessed through this interface. If the target-specific connection class implementing this interface does not support handling of NDEF messages, the methods defined in this connection must throw ContactlessException.

NDEFTagConnection extends the Generic Connection Framework (GCF) architecture. It defines a new protocol to be used when communicating with contactless targets that have NFC Forum formatted data. The URL required to open the connection to the target can be retrieved from TargetProperties received in the targetDetected notification.

There can be only one write operation ongoing at once and all other read and write attempts during that time will cause an IllegalStateException to be thrown.


Method Summary
 NDEFMessage readNDEF()
          Reads NFC Forum formatted data from the target.
 void writeNDEF(NDEFMessage message)
          Writes NFC Forum formatted data in the NDEF message to the target.
 
Methods inherited from interface javax.microedition.io.Connection
close
 

Method Detail

readNDEF

NDEFMessage readNDEF()
                     throws ContactlessException,
                            java.io.IOException

Reads NFC Forum formatted data from the target. This method blocks until reading is completed or the connection to target is lost.

The API implementation must read the whole NDEFMessage from the target at once. The API implementations may support data buffering. As the length of the target availability in the RFID field cannot be predicted, some hardware may try to read the content of the tag immediately once it appears to the interrogation field.

Returns:
NDEF message read from the target, null if target does not contain any data
Throws:
ContactlessException - if NFC Forum formatting is not supported by the target
java.lang.IllegalStateException - if write operation is ongoing
java.io.IOException - if connection to the target is lost or it has been closed

writeNDEF

void writeNDEF(NDEFMessage message)
               throws ContactlessException,
                      java.io.IOException

Writes NFC Forum formatted data in the NDEF message to the target. This method overwrites all the existing data on the target and it blocks until writing is completed or the connection to target is lost.

Writing data to the target may fail for various reasons. The API implementation must read the newly written data right after the write operation and make sure that all data was written correctly to the target. Returning from this method must mean that writing was successful. If writing failed an IOException is thrown.

Parameters:
message - NDEF message to be written to the target
Throws:
ContactlessException - if NFC Forum formatting is not supported by the target
java.lang.NullPointerException - if message is null
java.lang.IllegalArgumentException - if message does not contain any NDEF records
java.lang.IllegalStateException - if other write operation is ongoing
java.io.IOException - if writing data to the target failed, connection to the target is lost or it has been closed
java.lang.SecurityException - if the application does not have permission to write to a target


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