Java Reference
In-Depth Information
Listing 14-1. Setting the Payload of a TextMessage Instance
String receiver = "+18885551212";
String port = "1234";
String address = "sms://" + receiver + ":" + port;
MessageConnection c = null;
try {
c = (MessageConnection) Connector.open(address);
TextMessage t = (TextMessage) c.newMessage(
MessageConnection.TEXT_MESSAGE);
t.setAddress(address);
t.setPayloadText("Hello world!");
c.send(t);
} catch (Exception e) {}
finally {
if (c != null) {
try {
c.close();
} catch (Exception e) { /* recover */}
}
}
This code begins by creating a MessageConnection instance and using it to create a
new TextMessage instance. Next, it sets the recipient address of the TextMessage instance
and sets its payload to the message "Hello world!" before sending the message.
Note If you're familiar with telephony protocols, especially SMS, you know that SMS messages can be
encoded in any one of a number of different ways depending on the character set, network operator, and even
the bearer network used by the network operator. Mercifully, the WMA implementation is responsible for han-
dling message encoding and decoding to whatever protocols the handset and bearer network might require.
Setting and Getting the Payload of a BinaryMessage
Like TextMessage , BinaryMessage has a simple interface to manage its payload, treating the
payload as an array of byte s. The getPayloadData and setPayloadData methods are analo-
gous to getPayloadText and setPayloadText .
When people send binary SMS messages, the payload is typically small images or poly-
phonic ring tones, which the handset and SMSC encode and decode as Enhanced Messaging
Service (EMS) objects. Unfortunately, the WMA implementation does not support EMS
encoding or decoding, so short of writing your own codec, you can't directly interoperate with
 
Search WWH ::




Custom Search