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
import javax.wireless.messaging.*;
import javax.microedition.io.*;
...
try {
String addr = "sms://" + this.phone;
MessageConnection conn = (MessageConnection) Connector.open(addr);
TextMessage msg =
(TextMessage)conn.newMessage(MessageConnection.TEXT_MESSAGE);
msg.setPayloadText("SMS Demo to " + text );
conn.send(msg);
} catch (IllegalArgumentException iae) {
//do something
} catch (Exception e) {
//do something
}
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]
October 9th, 2008 at 7:26 am
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?
January 3rd, 2010 at 8:06 pm
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
October 24th, 2010 at 4:46 pm
To answer NickFl’s question:
Netbeans IDE (to date v6.9.1) does not use a GSM modem to send a real SMS to your phone.
To answer Akash’s problem:
I had the same problem using the Eclipse IDE (Pulsar /w Java ME SDK v3.0). The problem can be fixed by removing JSR205 (WMA v2.0) from the default device’s library. Alternately, if you want to do SMS as well as MMS, remove JSR120 (making sure JSR205 or better is added).
November 1st, 2010 at 4:32 pm
Superb information and facts for upload files for having myself get started. I most certainly will keep this particular website link and return to it.
November 1st, 2010 at 4:38 pm
Superb information and facts for upload files for having myself personally get moving. I most certainly will keep this particular website link and return to this.
March 20th, 2011 at 12:58 pm
Hey. Nice Post