简体   繁体   English

如何使用pushregistry读取j2me midlet中收到的消息?

[英]How to read recieved messages in j2me midlet using pushregistry?

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

You should use the PushRegistry mechanism for this. 您应该使用PushRegistry机制。 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. 为此,您应在.jad文件中标记您的应用程序对传入的SMS做出反应并标记SMS权限。 Put these properties to the JAD file: 将这些属性放到JAD文件中:

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 . 请注意,您应该使用自己的包和MIDlet名称 In addition to that you should use the same port for SMS sending as it was defined in the JAD (10214 in the example). 除此之外,您应该使用与JAD中定义的SMS发送相同的端口 (示例中为10214)。

After that when your MIDlet starts, you should call your SMS receiver code to get the SMS: 在你的MIDlet启动之后,你应该拨打你的短信收件人代码来获取短信:

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 更多信息: 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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