Code sample to Send SMS from a J2ME application.

By: Leon Emailed: 1608 times Printed: 2075 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

A java application, where on making a Push to talk call, and the call does not get matured due the the callers phone being busy in another call, busy in packet data, switched off or not in coverage, the java appplication installed in the callers phone should send out a sms, automatically to the called number. The number to send the SMS is taken from the phone book for the called number.

Here at at first we created a form called send sms and added commands to exit and send.

On clicking the send the control goes to public void sendit(String paramString1, String paramString2). where it first creates a connection with defined addree and and then creates an empty msg of type text. We then added the text that has to be sent and the pass that in the url of the address

 public void startApp()
 {
   this.display = Display.getDisplay(this);
   this.form = new Form("send sms");
   this.text = new TextField("number", "", 256, 0);
   this.send = new Command("send", 4, 1);
   this.exit = new Command("exit", 3, 2);
   this.form.append(this.text);
   this.form.addCommand(this.send);
   this.form.addCommand(this.exit);
   this.form.setCommandListener(this);
   this.display.setCurrent(this.form);
 }

 public void pauseApp()
 {
 }

 public void destroyApp(boolean paramBoolean)
 {
 }

 public void commandAction(Command paramCommand, Displayable
paramDisplayable) {
   if (paramCommand == this.exit) {
     notifyDestroyed();
   }
   if (paramCommand == this.send) {
     this.number = this.text.getString();
     System.out.println("in loop" + this.number);
     this.message1 = "please call me back";
     sendit(this.message1, this.number);
   }
 }

 public void sendit(String paramString1, String paramString2)
 {
   this.phoneNumber = paramString2;
   this.message = paramString1;
   StringBuffer localStringBuffer = new StringBuffer(20);

   String str = "sms://" + paramString2 ";

   this.form2 = new Form("");
   MessageConnection localMessageConnection = null;
   try
   {
     localMessageConnection = (MessageConnection)Connector.open(str);

     TextMessage localTextMessage =
(TextMessage)localMessageConnection.newMessage("text");
     localTextMessage.setAddress(str);
     localTextMessage.setPayloadText(paramString1);
     localMessageConnection.send(localTextMessage);

     this.form2.append("message sent");
     this.display.setCurrent(this.form2);
   }
   catch (Exception localException) {
     this.form2.append("phone number" + str + localException.getMessage());
     this.display.setCurrent(this.form2);
   }
 }

J2ME Home | All J2ME Tutorials | Latest J2ME Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(36)


1. View Comment

hi! im new in j2me applications so i just cleaned up your code and imported the packages that are required, well it does not have any syntax error except that when i run it using the emulator i have configured with my IDE, IT DOES NOT SHOW THE EFFECT, the emulator just simply appears and quickly destroy. help me i really need to learn j2me its quite interesting though.

View Tutorial          By: resego at 2010-08-04 07:29:29
2. View Comment

we want to learn j2me

View Tutorial          By: vijay at 2010-09-27 02:34:59
3. View Comment

hi.I am new in j2me and really want to learn more.was wondering if you could put up more tutorials on about everything there is to know please ,will be more than honored to have them.

View Tutorial          By: grace at 2010-10-25 10:40:32
4. View Comment

hi.I am new in j2me and really want to learn more so please send me full j2me tutorail on my e-mailid.

View Tutorial          By: Deepak kumar at 2010-11-15 03:04:15
5. View Comment

Hi every one. I am working on my project in j2me and wants to send email or sms using my application can any body help me and if possible upload or send complete code of the above sample...
thanks in advance,
Best regards

wazir


View Tutorial          By: wazir at 2010-11-26 08:27:43
6. View Comment

I need code for read write mifare 1k card using Nokia 6131

View Tutorial          By: amarendra at 2010-12-02 21:12:08
7. View Comment

Hi All,

I am new to J2ME Application, My requirement is i need to send sms using emulator, please help me to do this, i got above code, i tries to resolve errors, but it showing me error ' TextMessage ', and ' MessageConnection ', can any one help to solve these errors

thank you in advance.


View Tutorial          By: golemnagesh at 2010-12-05 22:43:50
8. View Comment

Hallo every one. I am working on my project in j2me and wants to send email or sms using my application can any body help me and if possible upload or send complete code of the above sample...
thanks in advance,
Best regards


View Tutorial          By: radhe at 2010-12-14 08:08:25
9. View Comment

Hello every one. I am working on my project in j2me on application mobile data security and syncronization and wants to send email or sms using my application can any body help me and if possible upload or send complete code of the above sample...
thanks in advance,
Best regards


View Tutorial          By: Pradeep Reddy at 2011-01-04 05:15:51
10. View Comment

HI EVERY ONE I AM NEW IN J2ME SO I WANT TO LEARN SO CAN YOU TELL ANY BOOKS FOR REFERENCE

View Tutorial          By: KALAI at 2011-04-04 03:10:32
11. View Comment

Hi every one. I am working on my project in j2me and wants to send email or sms using my application can any body help me and if possible upload or send complete code of the above sample...
thanks in advance,


View Tutorial          By: Anonymous at 2011-05-01 09:04:16
12. View Comment

I have a source code of j2ee. but i want to convert it into j2me code. plz send me the way. my program code is designed by using swing concept. and i got a jar file also.

View Tutorial          By: bangaram at 2011-06-07 09:28:45
13. View Comment

I am to learn J2ME

View Tutorial          By: ravi kumar at 2011-06-20 05:50:20
14. View Comment

I do my projest in j2me.so please send me your ideas how to start my project .send project title also.........thanks

View Tutorial          By: sivasakthivel.s at 2011-06-22 13:26:54
15. View Comment

please send detail informatoin about j2me.. send also the sample code and how to run the j2me programs..

View Tutorial          By: Saranya at 2011-07-06 03:00:21
16. View Comment

hello guys... plz help me in j2me i want to learn j2me so plz help me dear...
send me j2me project and codes any NIITians plz help...


View Tutorial          By: bishnu prakash at 2011-07-11 13:18:39
17. View Comment

hiii frds i want to run this program can i run using net bean ide 6.8,if yes then tel me full procedure......plz help me

View Tutorial          By: arun kumar ojha at 2011-07-20 00:59:10
18. View Comment

pls help me build a jar application for sending bulksms using my bulksms provider's API

View Tutorial          By: sam at 2011-08-13 11:31:03
19. View Comment

hi..i did a sms sending pgm..it works without error..but no messages are delivered..i think i hav problem with the port number..do anyone knows what is the port number used to send mesage..do reply..

View Tutorial          By: Ragesh Gopal at 2011-09-02 10:02:59
20. View Comment

hi.I am new in j2me and really want to learn more so please send me full j2me tutorail on my e-mailid.

View Tutorial          By: snehal at 2011-12-01 11:46:22
21. View Comment

hi.I am new in j2me and really want to learn more so please send me full j2me tutorial on my e-mail-id.

View Tutorial          By: Vicky Mittal at 2012-01-05 11:45:53
22. View Comment

sir , i am new in j2me and i want to learn more so please send me
some tutorials and some code on my email id

thanks..


View Tutorial          By: vipin Luhach at 2012-01-19 06:43:27
23. View Comment

does anyone know what exactly to use to desgn a phone application that sends sms.help me i want to begin programming.should i use java Me,elaborate for me

View Tutorial          By: andrew willy at 2012-01-29 14:51:13
24. View Comment

regarding 'TextMessage' and 'MessageConnection' error , one should import the correct packages for them.

View Tutorial          By: gaurav at 2012-04-24 11:57:17
25. View Comment

hi i am shahid i have made SMS application in j2me but the problems is when i send SMS it wants recommendation tell me the procedure that it sends SMS when the user click the send button and it doesn't want recommendation thanks

View Tutorial          By: shahid khan at 2012-06-18 13:19:06
26. View Comment

hi.I am new in j2me and really want to learn more so please send me full j2me tutorail on my e-mailid.

View Tutorial          By: A.vinothKumar at 2012-08-20 07:50:26
27. View Comment

Can u plz send me woking application (Send sms) J2ME code. M new to J2ME so i wanna learn it.. Thank you . (goelritanshu1991@gmail.com)..Thts my mail id.

View Tutorial          By: Ritanshu Goel at 2012-09-22 05:52:49
28. View Comment

Can u plz send me woking application (Send sms) J2ME code. M new to J2ME so i wanna learn it.. Thank you . (goelritanshu1991@gmail.com)..Thts my mail id.

View Tutorial          By: Ritanshu Goel at 2012-09-22 05:53:24
29. View Comment

hi.I am new in j2me and really want to learn more so please send me full j2me tutorail on my e-mailid.

View Tutorial          By: vinoth kumar. A at 2012-10-26 05:20:31
30. View Comment

what are the required equipments to run j2me

View Tutorial          By: messi at 2012-11-13 13:15:18
31. View Comment

i want to learn j2me basic to ....

View Tutorial          By: gopiraj at 2012-12-21 11:52:01
32. View Comment

vinod kumar for j2me app development we need one IDE either eclipse or netbeans and sun java w wireless tool kit

View Tutorial          By: saurabh dixit at 2013-04-18 09:59:23
33. View Comment

I am new to J2ME but this was really help full and make me enthusiastic to seek about more j2me, thanx verry very thanx

View Tutorial          By: Subhash at 2013-05-05 08:57:38
34. View Comment

i'm interest in j2me so i have to learn about j2me,can u send me

j2me codings....


View Tutorial          By: cha at 2013-10-14 13:17:22
35. View Comment

This is great, hope to learn more from this community. Bless you.

View Tutorial          By: Wamaguru at 2014-07-12 09:05:30
36. View Comment

Hi ,
please i need j2me appliacation :
send and receive sms (the sms is an url ) and when we click on this url a video will be played and we can do play , pause


View Tutorial          By: youyou92 at 2014-12-01 18:20:52

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Leon
Code sample to Send SMS from a J2ME application.

More Tutorials in J2ME
Code sample to Send SMS from a J2ME application.
Adding your own Application icon for your J2ME application (jar file)
Play a multimedia file in J2ME Program (Audio/Video) using MMAPI
Datagrams in J2ME (UDP Programming sample)
Client Server in J2ME (Socket Programming sample)
Using HttpConnection in J2ME (Retrieve web content from a website to a phone)
Using HTTP vs UDP vs Socket in J2ME
RMSCookieConnector - Using Cookies in J2ME
POST UTF-8 encoded data to the server in J2ME
lists, forms, choices, gauges, text fields, text boxes in J2ME
Using List to create a Menu and Menu items in J2ME
Using alerts and tickers in J2ME
J2ME Canvas sample to show games programming in J2ME
Timer and TimerTask example in J2ME
List of GPRS Access points for all countries

More Latest News
Most Viewed Articles (in J2ME )
GUI components and menu based J2ME Applications.
'LINK.EXE' is not recognized as an internal or ext
Code sample to Send SMS from a J2ME application.
What is J2ME?
Your first J2ME program and a midlet lifecycle explained.
RMS Basics in J2ME
List of GPRS Access points for all countries
Y.S. Sun Green Building Research Center
Sample J2ME code that shows various functionality of RMS.
A sample J2ME midlet that shows an example of using a Timer and a TimerTask.
Gauge sample program in J2ME
Sample program to draw a arc in J2ME
The MIDP Networking Model in J2ME
Using List to create a Menu and Menu items in J2ME
RMSCookieConnector - Using Cookies in J2ME
Most Emailed Articles (in J2ME)
Using HttpConnection in J2ME (Retrieve web content from a website to a phone)
What is J2ME?
DateField sample program in J2ME
Gauge sample program in J2ME
RMS Basics in J2ME
Y.S. Sun Green Building Research Center
Play a multimedia file in J2ME Program (Audio/Video) using MMAPI
Code sample to Send SMS from a J2ME application.
Download a file over a network in J2ME midlet
How to load J2ME applications to the IDEN handsets
Sample Java program shows how to Read a file over a network using J2ME midlet
Sample J2ME code that shows various functionality of RMS.
GUI components and menu based J2ME Applications.
java.lang.SecurityException: MIDP lifecycle does not support system exit.
Ticker sample program in J2ME