WMA (Wireless Messaging API) is a wireless messaging api defined in MIDP 2.0. These apis are designed to handle text, binary and multipart messages. To make a connection, the application obtains an object implementing the MessageConnection from the Connector class by providing an URL connection string that identifies the address.

 /* Make a connection */
public boolean connectSMSServer() 
{
  try 
  {
    messageConnection messageConnection = 
      (MessageConnection)Connector.open("sms://:" + port);
    messageConnection.setMessageListener(this);
  }
  catch (Exception e) {
  }
}

/* Send text message */
public void sendTextmessage(String address,String message) 
{
  try 
  {
    //creates a new TextMessage
    TextMessage textMessage = (TextMessage)messageConnection.newMessage(
            MessageConnection.TEXT_MESSAGE, address);
    textMessage.setPayloadText(message);
    messageConnection.send(textMessage);
  } 
  catch (Exception e) {
  }
}

/* Recieve text message */
public void receiveTextMessage() 
{
  try 
  {
    Message message = messageConnection.receive();
    if (message instanceof TextMessage) 
    {
      TextMessage textMessage = (TextMessage)message;
    } 
    else 
    {
      //Message can be binary or multipart
    }                   
  } 
  catch (Exception e) {
  }
}

/* Notify Incoming Message */
public synchronized void notifyIncomingMessage(MessageConnection conn) 
{
  //notiy thread of incoming message
  synchronized (this)
  {
    notify();
  }
}

/* Close Connection */
public void closeConnection() 
{
  if (messageConnection != null) 
  {
    try 
    {
      messageConnection.setMessageListener(null);
      messageConnection.close();
    } 
    catch (Exception e) {
    }
    }
  }
}

 Related Tips