Revision as of 02:49, 29 August 2012 by hamishwillee (Talk | contribs)

How to send text SMS in Java ME

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Code ExampleArticle
Created: SergioEstevao (15 Nov 2007)
Last edited: hamishwillee (29 Aug 2012)

WMAPI allows Java ME applications to access messaging functionalities, as sending and receiving SMS and MMS messages. This article explains how to use it to send a simple text message.



The following Java ME tip explains a method of sending text messages using WMAPI. In the program TextMessage interface represents a text message. The setPayloadText() method sets the characters in the message.

JavaME HowToSendTextSMS.png

  public boolean sendSms(String number, String message){
boolean result = true;
try {
//sets address to send message
String addr = "sms://"+number;
// opens connection
MessageConnection conn = (MessageConnection) Connector.open(addr);
// prepares text message
TextMessage msg =
//set text
// send message
} catch (SecurityException se) {
// probably the user has not allowed to send sms
// you may want to handle this differently
result = false;
} catch (Exception e) {
result = false;
return result;


You can download a sample MIDlet showing the code presented in this article here: Media:HowToSendTextSMSMIDlet.zip


  • Remember that a single message has a maximum size (140 bytes, which translates to 160 7-bit characters). If your message is too long to fit in one message it can be splitted to a maximum of three SMS, this is handled automatic by the WMA implementation.
  • Potentially-blocking operations, like sending a text message, should always be performed in separate threads, to avoid blocking the main MIDlet thread.

Related resources

299 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.