1

i don't know how to read received messages in mobile device using J2ME midlet.Actually I have been sending the messages to other mobiles using SMS gateway.The sms gateway reply to the same mobile device,but i want to read the reply message on the device directly, not going to check the inbox.how to do this in j2me midlet using the PushRegistry concept.please give me the good idea or sample code for me...thanks in advance.

NoNaMe
  • 6,020
  • 30
  • 82
  • 110
cheliyan
  • 1,679
  • 3
  • 16
  • 22

1 Answers1

3

You should use the PushRegistry mechanism for this. In order to do so, you should mark in the .jad file that your application reacts to incoming SMS and also mark the SMS permission. Put these properties to the JAD file:

MIDlet-Push-1: sms://:10214,hu.bute.daai.example.sms.MidletSMSPushDemo,*
MIDlet-Permissions: javax.microedition.io.PushRegistry, javax.microedition.io.Connector.sms, javax.wireless.messaging.sms.receive

Please note that you should use your own package and MIDlet name. In addition to that you should use the same port for SMS sending as it was defined in the JAD (10214 in the example).

After that when your MIDlet starts, you should call your SMS receiver code to get the SMS:

public class MidletJSMSProxy extends MIDlet {
    public void startApp() {
        initalize();
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void initSMSReceive() {
        new Thread() {
            public void run() {
                MessageConnection conn = null;
                try {
                    String url = "sms://:10214";
                    MessageConnection conn = (MessageConnection) Connector.open(url);
                     TextMessage message = (TextMessage)conn.receive();
                    System.out.println("SMS: "+message.getAddress()+" - "+message.getPayloadText());
                }
                catch(Exception e){
                    e.printStackTrace();
                } finally {
                    try {
                        if (conn != null)
                            conn.close();
                    } catch(Exception e){
                        e.printStackTrace();
                    }
                }
            }
        }.start();
    }
}

More info: http://www.developer.nokia.com/Community/Wiki/How_to_launch_a_MIDlet_remotely_via_SMS_or_locally_via_an_Alarm_with_PushRegistry_in_Java_ME

gnat
  • 6,213
  • 108
  • 53
  • 73
peekler
  • 330
  • 2
  • 10