java left logo
java middle logo
java right logo
 

Home arrow Java ME Tips arrow MIDP arrow Sending/Receiving SMS on J2ME device
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 3942
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
Sending/Receiving SMS on J2ME device E-mail
User Rating: / 151
PoorBest 

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


 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.