Java Reference
In-Depth Information
In Listing 11-2,
Sender
is a singleton; the static
getInstance()
factory method is used to get
the one and only instance. The
sendMsg()
method is used by
SMSMIDlet
to send the SMS message.
It assigns the incoming arguments to member variables, and then starts a thread to send the
message. The
mSending boolean
flag is used to avoid reentrant calls and to stop the MIDlet from
shutting down if message sending is in progress. The actual work of sending SMS messages is
performed in the
sendSMS()
method. The
sendSMS()
method is always called from a new thread.
sendSMS()
opens a new
MessageConnection
using a specified address and sends a text message
to the destination.
Testing SMSMIDlet with WTK 2.x WMA Console
You can easily test
SMSMIDlet
, or any SMS application, using a utility called the WMA console in
WTK 2.x. To access the WMA console, select File
➤
Utilities from KToolbar. Then click the
Open Console button in the WMA box.
To test
SMSMIDlet
, first start an instance in an emulator. Answer yes to the security question
when it starts up. Note on the title bar of the emulator that a phone number, beginning with
a + (plus sign), has been assigned to the emulator. By default, it will be
+5550000
. This is the
address of the emulator instance.
Now, start the WMA console. You will note that the WMA console is also assigned a phone
number beginning with a + sign. Click the Send SMS button. Select the address of the emulator
instance on the
Text SMS
tab, enter
1234
into the
Port
box, and then enter
red
for the message.
Click the Send button. Note that the
SMSMIDlet
instance now displays an image with a red back-
ground. Try sending an SMS message containing “blue” and observe how the
SMSMIDlet
instance
changes the graphics to a blue background.
Next, enter the address of the WMA console into the “Connect to:” text field of the
SMSMIDlet
instance. Then select Send Red from the menu of
SMSMIDlet
. Note that the console displays a
message to indicate receipt of the SMS message. Figure 11-3 shows the WMA console interacting
with
SMSMIDlet
.
Instead of using the WMA console, you can also start two emulator instances of
SMSMIDlet
and send SMS messages between them.
Search WWH ::
Custom Search