简体   繁体   中英

How to read recieved messages in j2me midlet using pushregistry?

我不知道如何使用J2ME midlet读取移动设备中收到的消息。实际上我一直在使用短信网关将消息发送到其他手机。短信网关回复同一个移动设备,但我想阅读回复消息设备直接,而不是检查inbox。如何使用PushRegistry概念在j2me midlet中执行此操作。请为我提供好主意或示例代码...在此先感谢。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM