Java Reference
In-Depth Information
The WMA is a compact API containing just two packages:
javax.microedition.io contains the platform network inter-
faces modified for use on platforms supporting wireless messaging
connection, in particular an implementation of the Connector class
for creating new MessageConnection objects.
javax.wireless.messaging defines APIs which allow applica-
tions to send and receive wireless messages. It defines a base interface,
Message ,fromwhich BinaryMessage and TextMessage both
derive. It also defines a MessageConnection interface, which pro-
vides the basic functionality for sending and receiving messages, and
a MessageListener interface for listening to incoming messages.
In this section, we consider sending and receiving SMS messages. We
then go on to show how to use the Push Registry API to register an
incoming SMS connection with a MIDlet.
2.10.1 Sending Messages
Sending an SMS message using the WMA could not be simpler, as the
code paragraph below shows:
String address = "sms://+447111222333";
MessageConnection smsconn = null;
try {
smsconn = (MessageConnection)Connector.open(address);
TextMessage txtMessage = (TextMessage)
smsconn.newMessage(MessageConnection.TEXT_MESSAGE);
txtmessage.setPayloadText("Hello World");
smsconn.send(txtMessage);
smsconn.close();
} catch (Exception e)
{
// handle
}
The URL address syntax for a client-mode connection has the following
possible formats:
sms://+447111222333
sms://+447111222333:1234
The first format above is used to open a connection for sending a
normal SMS message, which will be received in an inbox. The second
format is used to open a connection to send an SMS message to a Java
application listening on the specified port.
Search WWH ::




Custom Search