Java Reference
In-Depth Information
The Message interface is the super interface of both TextMessage and BinaryMessage , and
the preceding methods are available for both types of messages. The getAddress() method
returns the recipient's address if it is an outgoing message, or the sender address if it is an
incoming message. In fact, incoming messages can be reused for replies by just setting a new
payload.
The setAddress() method can be used to set the destination address for an outgoing
message. The destination address is set automatically when you're using a client mode
MessageConnection to create new messages. You will only need to call setAddress() if you're
using a server mode MessageConnection to create new messages.
Another method on the Message interface provides access to the timestamp on the message:
public Date getTimestamp();
This getTimestamp() method will return the timestamp on the message if it is available.
Receiving CBS Messages
Cell Broadcast Service, or CBS, is a carrier version of SMS. It enables a cell phone operator to
broadcast messages to a group of cell phone users. A WMA application can only receive CBS
messages.
There are no additional interfaces or classes for handling of CBS. You use the same mech-
anism as receiving SMS messages. However, the MessageConnection for CBS can only be opened
in the server (receiver) mode, since it is not possible to send CBS messages. For example:
conn = (MessageConnection) Connector.open("cbs://:12345");
msg = conn.receive(); // Blocking for message
The digits 12345 in this case do not refer to a WMA-managed port as in SMS; instead, they
serve as a message identifier. Message identifiers are a CBS-specific concept. They may repre-
sent different information channels that you can subscribe to. You need to consult your carrier
for the available message identifiers if you are developing software to process CBS messages.
Do not call send() on a CBS MessageConnection . Only phone network operators can broadcast
CBS messages. If you do call send(), you will get an IOException . Since CBS messages do not
carry any timestamp, calling getTimeStamp() on the message always returns null.
Working with SMS APIs
Let's put some of this to work. SMSMIDlet is a MIDlet that can send and receive SMS messages.
The GUI of SMSMIDlet is shown in Figure 11-2.
SMSMIDlet can be used to receive or send SMS messages. SMSMIDlet listens at port 1234 . If
the SMSMIDlet receives an SMS text message containing the word “red”, an image with a red
background will be displayed by the MIDlet. If the SMS text message received contains the
string “blue”, an image with a blue background will be displayed.
In Figure 11-2, you can enter the address that you want to send SMS messages to into the
“Connect to:” text field. Using the menu, you can then send either a “red” or “blue” SMS message
to the recipient.
Search WWH ::




Custom Search