Java Reference
In-Depth Information
Note This example sends an image included with the MIDlet at compile time. Generating and encoding
images dynamically to send with the WMA can be difficult. The Mobile Media API (MMAPI), which I discuss in
Chapter 16, can generate JPEG images from a device's camera, but you generally cannot encode Image
objects to send with the WMA over MMS without additional code such as a PNG encoder.
Wrapping Up
The WMA, defined first in JSR 120 and extended in JSR 205, defines an extension to the
GCF that lets MIDlets send and receive SMS and MMS messages, as well as receive
SMS-CB messages. In essence, using it is the same as writing any other GCF-aware
application: you use the Connector 's open method as a factory for MessageConnection
objects, which you can then use to create instances of specific Message subclasses to
represent messages for the device to send or messages that the device has received.
The MessageConnection instance you create with the GCF acts as a factory for mes-
sages; you can create new MO messages using its newMessage method, passing the kind of
message you want to create, or you can wait for an incoming message by invoking its
receive method (which blocks the current thread until a message arrives). The WMA
defines the Message class to encapsulate the notion of an address and timestamp for mes-
sages. Subclasses of Message define specific semantics for text SMS messages, binary SMS
messages, and MMS messages: the TextMessage , BinaryMessage , and MultipartMessage
classes, respectively. Using these classes, you can set the message payload, or in the case
of MultipartMessage instances, you can manage multiple recipient addresses as well as the
various parts that constitute a message. Once you configure an outgoing message, you
can send it using the MessageConnection 's send method.
Using the WMA requires that your MIDlet have privilege. When packaging your
application, be sure to include the privileges for both the kind of message your applica-
tion uses as well as the direction (send or receive) of the messages your MIDlet uses in its
JAD file.
 
Search WWH ::




Custom Search