Before the AMS can start a certain application by a remote connection, the AMS needs to know some basic details. So MIDlets have to register at the AMS for push connections.
There are two ways an application can register: via either dynamic or static registration. With dynamic registration, the application takes care of the registration when it starts. With static registration, the registration information is in the jad file.
Dynamic registration means that the MIDlet is registered to the AMS at runtime. At registration, the AMS gets to know the URL of the connection, the MIDlet, and the filter (if any). The type of connection can be a datagram, sms, or socket, for example. The filter restricts which senders are valid for launching the requested MIDlet. The content of the filter depends on the type of connection. But with any type of connection, it must support the wildchars * and ?. With socket connections, the filter can be something such as 129.65.40.*. An asterisk (*) alone allows anything.
The registration of a connection is done with PushRegistry's method registerConnection(String connection, String midlet, String filter). Registering an alarm is done with the registerAlarm(String midlet, long time) method of PushRegistry class.
Here are some examples of how to use the registerConnection() method:
PushRegistry.registerConnection("socket://:200", this.getClass().getName(), "*"); PushRegistry.registerConnection("sms://:250", this.getClass().getName(), "*"); PushRegistry.registerConnection("datagram://:300", this.getClass().getName(), "*");
Static registration is done in the jad file, so you have to add a line in the jad file in the following format:
MIDlet-Push-<n>: <ConnectionURL>, <MIDletClassName>, <AllowedSender>
The parameters are the same as with dynamic registration. This is an example of static registration:
MIDlet-Push-1: sms://:200, PushMIDlet, * MIDlet-Push-2: socket://:250, ChatMIDlet, 128.128.128.*
Static registrations are removed automatically whenever the AMS uninstalls the MIDlet or the MIDlet suite. If you want to remove a dynamic registration, you can use the unregisterConnection(String connection) method of PushRegistry class.
Required Software for the Example
To develop the following example, you need to install the following software:
JDK version 1.4.1
J2ME Wireless Toolkit 2.0