|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface ISO14443Connection
This interface defines access to the ISO 14443-4 compliant contactless
smart card. With this interface application can communicate with
contactless smart card using APDU commands. This interface does not replace
APDUConnection interface specified in JSR 177. Implementation of
this class may take advantage of JSR 177. The slot number
needed to open an APDUConnection to the external smart card
may be provided though the TargetProperties.getProperty
method.
Following example shows how this connection can be used. It opens an
ISO14443Connection to the discovered external smart card and
sends APDU command to it.
import java.io.IOException;
import javax.microedition.contactless.*;
import javax.microedition.contactless.sc.ISO14443Connection;
import javax.microedition.io.Connector;
//
// Example class of how to use SmartCardConnection in JSR 257 Contactless
// Communication API
//
public class TestSmartCard implements TargetListener, TransactionListener {
public TestSmartCard() {
try {
DiscoveryManager dm = DiscoveryManager.getInstance();
dm.addTargetListener(this, TargetType.ISO14443_CARD);
dm.addTransactionListener(this);
}
catch (ContactlessException ce) {
}
}
// Smart card target has been found (reader mode)
public void targetDetected(TargetProperties[] properties) {
TargetProperties target = properties[0];
Class[] classes = target.getConnectionNames();
for (int i=0; i<classes.length; i++) {
try {
if (classes[i].equals(Class.forName(
"javax.microedition.contactless.sc.ISO14443Connection")
)) {
String url = target.getUrl(classes[i]);
// Open connection to external smart card
ISO14443Connection smc =
(ISO14443Connection)Connector.open(url);
// Generate command
// Send command to smart card
byte[] response = smc.exchangeData(commands);
// handle response
}
}
catch (ClassNotFoundException e) {
// handle exception
}
catch (IOException e) {
// handle exception
}
catch (ContactlessException ce) {
// handle exception
}
}
}
// External reader has been detected (tag emulation mode)
public void externalReaderDetected(byte slot) {
// update the UI based on the application ID received
}
}
| Method Summary | |
|---|---|
byte[] |
exchangeData(byte[] data)
Exchanges APDU commands with an external smart card using ISO14443-4 communication. |
| Methods inherited from interface javax.microedition.io.Connection |
|---|
close |
| Method Detail |
|---|
byte[] exchangeData(byte[] data)
throws java.io.IOException,
ContactlessException
data - APDU commands to be sent to the smart card
ContactlessException - if the operation is not supported by the
API implementation
java.lang.NullPointerException - if data is null
java.lang.IllegalArgumentException - if data is an empty
array
java.io.IOException - if connection has been closed
java.io.InterruptedIOException - if connection is closed during exchange
operation
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||