Java Reference
In-Depth Information
This example simply loops over the inbound connections provided by listConnections
and receives each inbound message, processing each in turn.
Registering Dynamically for Incoming Messages
When you specify the URL of an inbound connection in your MIDlet's JAD file, you're indi-
cating your interest in an inbound connection to the AMS statically —that is, at the time at
which you build and package your application. There will be times when you won't want to
do this—for example, if your application lets the user determine whether or not it should
launch when the device receives an incoming message. To permit the user to determine
whether or not your MIDlet should respond to incoming messages, your application can
register its interest in inbound requests dynamically —that is, at runtime.
Dynamic registration for inbound messages is easy: simply invoke PushRegistry.
registerConnection and pass the inbound connection URL, the class to launch, and the
filter, as shown in Listing 14-5.
Listing 14-5. Dynamically Registering for an Inbound Connection Using the Push Registry
PushRegistry.registerConnection("sms://:1234",
"com.apress.rischpater.SMSMIDlet",
"*" );
Doing this is functionally equivalent to listing the inbound end-point URL in a
MIDlet-Push entry; once you do this, the AMS sends inbound connection requests to your
MIDlet when it's not running. To disable this—in other words, to cancel the registration—
invoke PushRegistry.unregisterConnection , passing just the URL you passed to
registerConnection :
PushRegistry.unregisterConnection("sms://:1234");
Once you do this, the AMS will no longer notify your MIDlet of inbound connections
on the GCF URL you specify.
Using PushRegistry APIs
Chapter 4 showed you how to register for alarms, and the previous listings showed you
how to register incoming connections. You can also determine the filter you previously
specified for an inbound connection or the MIDlet responsible for handling an inbound
connection.
 
Search WWH ::




Custom Search