Java Reference
In-Depth Information
If the message is an instance of
BinaryMessage
, then the corre-
sponding
getPayloadData()
method returns a byte array. In practice,
of course, we need the receiving application to listen for incoming mes-
sages and invoke the
receive()
method upon receipt. We achieve
this by implementing a
MessageListener
interface for notification
of incoming messages. The
MessageListener
mandates one method,
which is called on registered listeners by the system when an incoming
message arrives:
public void notifyIncomingMessage(MessageConnection conn)
The
MessageConnection
interface supplies the following method
to register a listener:
public void setMessageListener(MessageListener l)
For more details on the use of the
MessageListener
interface,
please download the source code, JAD and JAR files for the
SMSChat
MIDlet from this topic's website.
2.10.3 WMA and the Push Registry
When implemented in conjunction with MIDP 2.0, the Wireless Messag-
ing API can take advantage of the push registry technology. A MIDlet suite
lists the server connections it wishes to register in its JAD file, or manifest,
by specifying the protocol and port for the connection end point. The
entry has the following format:
MIDlet-Push-<n>: <ConnectionURL>, <MIDletClassName>, <AllowedSender>
In this example, the entry in the JAD file would be as follows:
MIDlet-Push-1: sms://:1234, SMSMIDlet, *
field acts as a filter indicating that the AMS
should only respond to incoming connections from a specific sender.
For the SMS protocol,
The
<
AllowedSender
>
entry is the phone
number of the required sender (note the sender port number is not
included in the filter). Here the wildcard character '*' indicates 'respond
to any sender'. The AMS responds to an incoming SMS directed to the
specified
MessageConnection
by launching the corresponding MIDlet
the
<
AllowedSender
>