Java Reference
In-Depth Information
public static void readMessage()
{
}
public static void writeMessage()
{
}
}
It's important that registration begin with a determination of which target types are
supported; you can determine which target types a specific implementation of the API
supports by invoking the DiscoveryManager 's static getSupportedTargetTypes to obtain a list
of supported types.
Tip Always enumerate the supported types! Some versions of the Contactless Communication API may
support additional types of near-field devices beyond what I discuss here; see the documentation that
accompanies a specific Java ME device and implementation of the API for details.
Once the code tests to ensure that the implementation supports the NDEF type, it
registers a listener using the addTargetListener method. If you want to listen for multiple
target types, you can do so using a single DiscoveryManager ; you can either specify sepa-
rate objects to respond to the targetDetected event or handle the detected target type
within the targetDetected method.
After registration, the API implementation invokes your listener's targetDetected
method when the device encounters a target of the appropriate type; at this point, your
code should begin communicating with the device. This may be a place where your
application needs to launch a separate thread, especially if the communications
exchange consists of more than just a command or two.
Communicating with Contactless Targets
Unsurprisingly, communication with targets is via the ubiquitous GCF; the means to
communicate with various targets are embodied in Connection subclasses, as you see in
Figure 15-3.
 
Search WWH ::




Custom Search