How to send SMS using WMA JSR-120 in JavaME J2ME

August 23rd, 2007 Posted in J2ME / JavaME, newbie

Here a basic way on how to send SMS programatically from within JavaME / J2ME application using Wireless Messaging API (JSR-120).

WMA JSR-20 Code Snippets

JAVA:
  1. import javax.wireless.messaging.*;
  2. import javax.microedition.io.*;
  3.  
  4. ...
  5.     try {
  6.         String addr = "sms://" + this.phone;
  7.         MessageConnection conn = (MessageConnection) Connector.open(addr);
  8.         TextMessage msg =
  9.         (TextMessage)conn.newMessage(MessageConnection.TEXT_MESSAGE);
  10.         msg.setPayloadText("SMS Demo to " + text );
  11.        
  12.         conn.send(msg);
  13.     } catch (IllegalArgumentException iae) {
  14.         //do something
  15.        
  16.     } catch (Exception e) {
  17.         //do something
  18.     }

As with other networking code, you need to execute this in a separate thread from the main MIDlet application (i.e commandAction), to avoid potential deadlocks.

Download complete working MIDlet application that demonstrates Wireless Messaging API code : SMSDemo.zip

[tags]java,j2me,javame,midlet,mobile,application,jsr-120,nokia[/tags]

 

Random Posts

2 Responses to “How to send SMS using WMA JSR-120 in JavaME J2ME”

  1. NickFl Says:

    This is very good example for the newbies like myself.
    The only problem I had with it, I tried to run it from the NetBeans 6.1 IDE and it didn’t work :( (?)
    I mean, message was not received.
    But then I loaded built jar/jad files on my Nokia 6265i and run it.
    And it worked!
    So, what could be wrong with the NetBeans IDE?



  2. Akash Says:

    Hi I am getting the following error

    Exception in thread “main” java.lang.UnsatisfiedLinkError: getProperty0
    at com.sun.midp.Configuration.getProperty0(Native Method)
    at com.sun.midp.Configuration.getProperty(Unknown Source)

    Can anybody help me



Leave a Reply