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]

 

Random Posts


6 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



  3. Osmund Says:

    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).



  4. send files java Says:

    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.



  5. rapidshare search music Says:

    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.



  6. Garfield Matuck Says:

    Hey. Nice Post



Leave a Reply

This blog is protected by dr Dave\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'s Spam Karma 2: 174428 Spams eaten and counting...