|Oracle® Java Micro Edition Software Development Kit Developer's Guide
Release 3.0.5 for Windows
The Contactless Communication API (
http://jcp.org/en/jsr/detail?id=257) is a Java ME optional package that allows applications to access information on contactless targets, such as Radio Frequency Identification (RFID) tags and bar codes. RFID tags are often used in business for item identification, article surveillance, and inventory. Each RFID contains a unique identification number used to identify a tagged object.
Using the JSR 257 API, an RFID reader can be built into a Java Wireless Client software phone stack, allowing the handset to read data from a tagged target and write data back to it. RFID readers use the 13.56 MHz radio frequency and the communication distance is usually less than 10 centimeters.
The Near Field Communication (NFC) Forum defines the NFC Data Exchange Format (NDEF) data packaging format. NDEF facilitates communication with an RFID tag, or between one NFC device and another. The Contactless Communication API provides a connection to any physical target that supports the NDEF standard, allowing applications to exchange data with any target tagged with NDEF formatting, regardless of actual physical type.
For an explanation of this implementation, see the Oracle Java Wireless Client Porting Guide.
The Java ME SDK provides a way to test contactless communication. The MIDlet running on the emulator waits to detect an RFID tag. You can simulate the tag communication using the emulator's external events generator to detect and attach the tag. You can use one of the tags included in the sample, or create tag files of your own, as described in Section 32.2, "Tag File Formats".
Launch the ContactlessDemo. The MIDlet notifies you that it is waiting for a tag.
In the emulator, choose Device > Contactless Communication. In the external events generator the tag emulator supplies three tags by default: hello, nested, and vcard.
To test the connection, select an available tag and press the Attach tag button.
In the emulator the MIDlet notifies you that the NDEF target is detected, displays the tag information, and prints the payload if it is a text record.
In the external events generator, press the Detach tag button to end the session.
Events are recorded in the log area. To clear the log, right-click and select delete text. To clear the emulator screen press the Clear soft button.
To create your own tag, create a tag file according to the NFC Data Exchange Format (NDEF). For a sample, see Section 32.2, "Tag File Formats".
In the external events generator, press the Create tag button, browse to select your tag file, and press Open. If the file is properly formed, the new tag is added to the available tags list.
You can use the Remove tag button to remove any tag from the list. If it's a tag you created, the original file on disk is not affected. If the default tags are removed, they will reappear when you restart the demo.
Optional. Instead of performing interactive actions in the external events generator, you can use a script to do the same thing.
Create a file as directed in Section 32.3, "Script Format". In the external events generator, click the Browse button to locate your script, then press Play.
Tags are created in XML format in accordance with the NFC and NDEF standards. To see how the sample files are formed, see: installdir
A sample file with several records might look like this:
<?xml version="1.0" encoding="UTF-8"?> <jsr257client> <UID>12-CD-45-67-89-AB-CD</UID> <TargetProperties> <TargetProperty>NDEF</TargetProperty> </TargetProperties> <NDEFMessage> <NDEFRecord> <Format>MIME</Format> <Name>text/example</Name> <Id>urn:company:product:ndef:payload:3</Id> <Payload>payload</Payload> </NDEFRecord> <NDEFRecord> <Format>MIME</Format> <Name>text/plain</Name> <Id>mimeid</Id> <Payload>Hello, MIME World!</Payload> </NDEFRecord> <NDEFRecord> <Format>URI</Format> <Name>
http://www.oracle.com/technetwork/java/javame/index.html</Name> <Id>jme</Id> <Payload>Java ME</Payload> </NDEFRecord> <NDEFRecord> <Format>NFC_FORUM_RTD</Format> <Name>urn:nfc:wkt:Sp</Name> <Id></Id> <Payload>smart-poster</Payload> </NDEFRecord <NDEFRecord> <Format>MIME</Format> <Name>text/x-vCard</Name> <Id>duke</Id> <Payload>BEGIN:VCARD VERSION:2.1 FN:Oracle TEL:+1-650-506-7000 ADR:500 Oracle Parkway;City: Redwood Shores; State: CA;94065 END:VCARD </Payload> </NDEFRecord> </NDEFMessage> </jsr257client>
You can use the external events generator buttons to attach and detach a tag, or you can write a script to perform these actions. The script syntax is as follows:
# Comment: # this is a comment # Tag definition: tag <tag name> <path to the tag xml file> # Attach tag: attach <tag name> # Delay. Ensures the tag is attached before other actions. wait <time in ms> # Print tag information: print <tag name> # Detach tag: detach <tag name>
This is a sample script:
tag C D:\MyTags\ccomtag.xml attach C print C wait 10000 detach C