Java – receive text messages using J2ME

I'm trying to send J2ME applications to send and receive text messages I finished the sending part of it, but I can't receive any messages

The following is what I tried to receive SMS;

try {
        MessageConnection conn = (MessageConnection) Connector.open("sms://:50001");
        conn.setMessageListener(new MessageListener() {
            public void notifyIncomingMessage(MessageConnection conn) {
                try {
                    Message msg;
                    msg = conn.receive();
                    if (msg instanceof TextMessage) {
                        TextMessage tmsg = (TextMessage) msg;
                        stringItem.setText("Msg: " + tmsg.getPayloadText());
                        System.out.println(tmsg.getPayloadText());
                    }
                    // else if(msg instanceof BinaryMessage) {
                    // .....
                    // } else {
                    // ......
                    // }
                } catch (IOException ex) {
                    ex.printStackTrace();
                } finally {
                    try {
                        conn.close();
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    }
                }
            }
        });
    } catch (Exception e1) {
        System.out.println(e1);
    }

But it didn't work... And there were no mistakes... What did I do wrong Can we receive messages using J2ME?

Code to send message: (Updated)

MessageConnection conn = (MessageConnection) Connector.open("sms://:50001");
TextMessage tmsg = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE);
tmsg.setPayloadText(message);
tmsg.setAddress("sms://" + number);
conn.send();

I have two different forms of sending and receiving functions What I do is install and launch applications in two different phones, send messages from one phone to another, and receive messages in the other

The message was successfully sent and received, but not in the application The message will go to the inbox of another mobile device

What can I do?

Solution

Try the 5000 port number

Some mobile phones have this port for SMS listeners

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>