Java Reference
In-Depth Information
public class ISO14443Example implements TargetListener {
byte[] commandAPDU = ...;
public ISO14443Example () {
try {
DiscoveryManager dm = DiscoveryManager.getInstance();
dm.addTargetListener(this, TargetType.ISO14443_CARD);
dm.addTransactionListener(this);
}
catch (ContactlessException e) { … }
}
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]);
ISO14443Connection smc =
(ISO14443Connection)Connector.open(url);
byte[] responseAPDU = smc.exchangeData(commandAPDU);
// do something with the response
}
}
catch (Exception e){…}
}
}
}
The detection process for an ISO 14443 target (or other RFID target, for that matter)
is exactly the same as for an NDEF-enabled one; simply specify a TargetType of ISO14443_
CARD to the DiscoveryManager 's addTargetListener interface. Once a target is detected, the
platform invokes the registered listener targetDetected , which can then exchange APDU
packets with the target.
If this interface looks familiar, it should; that's because ISO 14443 devices are close
kin to the wired smart cards supported by the optional SATSA API I discussed previously
in this chapter.
Caution You can only have a single connection open to a contactless target, due to hardware limitations
of most contactless target devices.
 
Search WWH ::




Custom Search