Push Registry in j2me

Chapter 7 - Push Registry

    Push Registry in j2me

  • Push Registry

    push registry pushes a message to a application and automatically launches the application.

    The push registrys described in the following three steps:

    1. The MIDlet registers a port along with the protocol name in the mobile device ,if any message arrives in the specified port with the protocol ,the AMS delivers it to the MIDlet.

    The registration is done statically using the Java ME application descriptor (JAD) file. The program can also perform dynamic registration using an API inside the application.

    2. From the server, a message is sent to the specific mobile device using the protocol and port where the MIDlet application is registered to listen.

    3. After the message is delivered to the mobile device, the AMS calls the MIDlet application, which has registered to listen to that particular port and particular protocol.

    Once the message is delivered to the MIDlet,the application process the message.An application may choose to open a screen, depending on the message, and allow the user to do some server transaction.

    Each push registration entry in the jad file contains the information: MIDlet-Push:

    • MIDlet-Push-:: The push registration attribute name. Multiple push registrations can be provided in a MIDlet suite.

    The numeric value for starts from 1 and must use consecutive ordinal numbers for additional entries. The first missing entry terminates the list. Any additional entries are ignored.

    • ConnectionURL: The connection string used in Connector.open().

    • MIDletClassName: The MIDlet responsible for the connection. The named MIDlet must be registered in the descriptor file or the jar file manifest with a MIDlet- record.

    • AllowedSender: A designated filter that restricts which senders are valid for launching the requested MIDlet.

    Pushing the message from the server to the mobile device leads to issues:

    Send a message to a particular device that has registered to listen to the socket stream on a specific port,the mobile phone wireless network IP.

    As many phones do not use the always-connected environment in the wireless network.

    sending a message to such a device is problematic and not be able to send a message to the device using the socket connection from the server.

    Using SMS as a trigger also involves some issues: Since the MIDP 2.0 specification defines the syntax for datagram and socket inbound connections and not for SMS connections.

    Its  not guaranteed that all the devices supporting MIDP 2.0 will be able to use SMS as a trigger for the push registry.

    In Wireless Messaging API (WMA 1.1)—an optional package over MIDP, which can support SMS—is now supported by many mobile devices, so there is a better chance that SMS will be supported by many devices as a trigger to the push registry.

    sending an SMS message from the server to the device is not straightforward, since multiple approaches are available.

    SMS service providers provide the APIs through send messages to the designated mobile phone from your server-side application.

    It requires a dependency on the SMS service provider and its special plans. The alternate way is to use a GSM modem, where used to interface the GSM modem with your server-side application.

    Each SMS message will cost the same as a message sent from a normal GSM mobile phone.Sending bulk SMS messages the providers SMS gateway may prove more cost effective for an enterprise application.

    PushRegistry (Receiving SMS) sms to receive through the specified port no. When it receives the sms the application automatically starts and check the message content.

    If the message content is a required one then it will send a message to the same number.

    MIDlet-Push-1: sms://:5001,SendApprooval,*
    SMS-Port: 5001
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.io.*;
    import javax.wireless.messaging.*;
    import java.util.Date;
    import java.io.*;
    * @author test
    public class SendApprooval extends MIDlet implements Runnable, CommandListener, MessageListener {
          private Display display;
          Date todaydate;
          private Command exitCommand;
          private Alert content, alert;
          Thread thread;
          String[] connections;
          boolean done;
          String smsPort, senderAddress, mess;
          MessageConnection smsconn = null, clientConn = null;
          Message msg;
          Displayable resumeScreen;
          public SendApprooval() {
                display = Display.getDisplay(this);
                smsPort = getAppProperty("SMS-Port");
                content = new Alert("");
                content.setString("Waiting for Authentication Request");
                exitCommand = new Command("Exit", Command.EXIT, 2);
                resumeScreen = content;
                public void startApp() {
                String smsConnection = "sms://:" + smsPort;
                if (smsconn == null) {
                      try {
                            smsconn = (MessageConnection) Connector.open(smsConnection);
                      } catch (IOException ioe) {
                connections = PushRegistry.listConnections(true);
                if ((connections == null) || (connections.length == 0)) {
                      content.setString("Waiting for Authentication Request");
                done = false;
                thread = new Thread(this);
          public void run() {
                try {
                      msg = smsconn.receive();
                      if (msg != null) {
                            senderAddress = msg.getAddress();
                            int k, j = 0;
                            for (k = 0; k <= senderaddress="" length="" -="" 1="" k="" if="" charat="" :="" j="=" 2="" break="" content="" setstring="" smsport="" msg="" instanceof="" textmessage="" mess="" getpayloadtext="" else="" stringbuffer="" buf="" byte="" data="" getpayloaddata="" for="" int="" i="" intdata="" 0xff="" 0x10="" append="" 0="" integer="" tohexstring="" equals="" give="" me="" rights="" try="" clientconn="" connector="" open="" catch="" exception="" e="" alert="" unable="" to="" connect="" station="" because="" of="" network="" problem="" settimeout="" 2000="" display="" setcurrent="" newmessage="" messageconnection="" text_message="" setaddress="" setpayloadtext="" approoved="" send="" null="" alerttype="" info="" forever="" tostring="" ioexception="" public="" void="" pauseapp="" done="false;" thread="" resumescreen="display.getCurrent();" destroyapp="" boolean="" unconditional="" smsconn="" close="" notifydestroyed="" showmessage="" string="" message="" displayable="" settitle="" error="" settype="" 5000="" commandaction="" command="" cmd="=" disp="" exitcommand="" dismiss_command="" false="" ex="" printstacktrace="" notifyincomingmessage="" conn="" waiting="" authentication="" request="" this="" start="" pre="">

    The PushRegistry maintains a inbound connections. An application can register the inbound connections with an entry in the JAD file or by dynamically calling the registerConnection method.

    public void displayConnections() {
        String[] allConnections = PushRegistry.listConnections(false);
        StringBuffer sbuf = new StringBuffer();
        if (allConnections != null && allConnections.length > 0) {
            for (int i = 0; i < allConnections.length; i++ ) {
        String str = sbf.toString();
    /*Register or Unregister an inbound connection*/
    public void regConnection() {
        try {
            String url = "socket://";
            String classname = "Midlet" //Midlet to be launched
                    if (register) {
                PushRegistry.registerConnection(url, classname, "*");
                    } else {
        } catch (IllegalArgumentException iae) {
        } catch (IOException ioe) {
    /*register an alarm*/
    public void setAlarm() {
        try {
            Date d = new Date();
            String classname = "Midlet"
                    long previousAlarmTime = PushRegistry.registerAlarm(
                    classname,d.getTime() + MILLISECONDS_TILL_ALARM);
        } catch (Exception e) {
    /*Connect to Url*/
    public void connectUrl() {
        try {
            String[] connections = PushRegistry.listConnections(true);
            if (connections != null && connections.length > 0) {
                for (int i = 0; i < connections.length; i++ ) {
                    ServerSocketConnection serverConnection = 
                    SocketConnection socketConnection = 
        } catch (Exception e) {

    The push registry's behavior can be simply described in 3 steps:

    1. The MIDlet registers a port along with the protocol name.

    The AMS delivers and wakes up the MIDlet when it detects incoming connection to that port. The registration is done statically using the JAD file, or it can perform dynamic registration within the MIDlet.

    2. A SMS or data connection is sent to the specific mobile device using the particular protocol and port where the MIDlet application is registered to listen.

    3. The AMS wakes up the MIDlet application. It used MIDlet's responsibility to process the data.

© 2015 by Learncertification All Rights Reserved. The certification names are the trademarks of their respective owners. Terms & Privacy Policy