Over a million developers have joined DZone.

Sending/Receiving SMS From MIDlets

DZone's Guide to

Sending/Receiving SMS From MIDlets

Free Resource

// Lets send an SMS now.
//get a reference to the appropriate Connection object using an appropriate url
MessageConnection conn = (MessageConnection) Connector.open("sms://:50001");
//generate a new text message
TextMessage tmsg = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE);
//set the message text and the address
tmsg.setAddress("sms://" + number);
//finally send our message

// Time to receive one.
//get reference to MessageConnection object
MessageConnection conn = (MessageConnection) Connector.open("sms://:50001");
//set message listener
   new MessageListener() {
      public void notifyIncomingMessage(MessageConnection conn) {
         Message msg = conn.receive();
         //do whatever you want with the message
         if(msg instanceof TextMessage) {
            TextMessage tmsg = (TextMessage) msg;
         } else if(msg instanceof BinaryMessage) {
         } else {

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}