Symbian
Symbian OS Library

FAQ-1141 How can I send an SMS message using the Wireless Messaging API so that it is received by a specific MIDlet?

[Index][spacer] [Previous] [Next]



 

Classification: Java Category: J2ME Wireless Messaging API
Created: 09/23/2004 Modified: 10/18/2004
Number: FAQ-1141
Platform: Symbian OS v7.0s, Symbian OS v8.0, Symbian OS v8.0a, Symbian OS v8.0b

Question:
How can I send an SMS message using the Wireless Messaging API so that it is received by a specific MIDlet?

Answer:
To send a SMS message so that it is received by a specific MIDlet it is necessary to specify a port number in the SMS address. This port number must correspond to port on which the target MIDlet is listening. Code to send the SMS message would look something like this.


    String address = "sms://+447111222333:1234";
    MessageConnection smsconn = null;
    try {
    smsconn = (MessageConnection)Connector.open(address);
    TextMessage txtMessage = (TextMessage)smsconn.newMessage(MessageConnection.TEXT_MESSAGE);
    txtmessage.setPayloadText("Hello World");
    smsconn.send(txtMessage);
    smsconn.close();
    } catch (Exception e) {
    //handle
    }


    For the remote MIDlet to receive the SMS message the MIDlet must have opened a MessageConnection listening on the specific port, for example

    MessageConnection conn = (MessageConnection) Connector.open("sms://1234");
    Message msg = smsconn.receive();

    If there is no MIDlet listening on the specified port when the SMS message is received by the remote phone, then the message will be delivered into the phone's inbox. On MIDP 2.0 phones one way to ensure that a MIDlet always receives a message sent to it is to register the appropriate SMSConnection with the Push Registry via the MIDlet-Push attribute in the JAD file. For example

    MIDlet-Push-1: sms://:1234, SMSMIDlet, *



    Also see FAQ-1142 How can I send an SMS message using the Wireless Messaging API so that it is received in the recipient's inbox?