You Are Here:

Community: Developer Discussion Boards

Reply « Previous Thread | Next Thread »

#1 Old Unhappy Sms sending through j2me.. - 2007-12-13, 07:28

Join Date: Nov 2007
Posts: 5
shankar.vaval
Offline
Registered User
hi i m new to j2me and i m developing Sms sending utility, i have writen the following code, n it is giving the error, can any one plese give suggestion on this...
Error:java.lang.IllegalArgumentException: Invalid sender address

My code :

import javax.microedition.io.Connector;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.wireless.messaging.*;

/**
* @author Shankar.Vaval
*/

public class SendTest extends MIDlet implements CommandListener
{
Thread t= new Thread();
public Display disp;
public Form mainfrm;
public Command sendCmd,exit;
public TextBox tb;
public String msg;
public Message m;
//
public TextField phno;
public TextField txtmsg;

public SendTest()
{

}

public void startApp() {
exit=new Command("Exit", Command.BACK, 2);
sendCmd = new Command("Send",Command.OK,1);
txtmsg=new TextField("Enter Message","",160,TextField.ANY);
phno=new TextField("Phone No:", "", 12, TextField.PHONENUMBER);
mainfrm=new Form("Sending TextMessage");
mainfrm.append(phno);
mainfrm.append(txtmsg);
mainfrm.addCommand(sendCmd);
mainfrm.addCommand(exit);
mainfrm.setCommandListener(this);
disp = Display.getDisplay(this);
disp.setCurrent(mainfrm);
}
public void commandAction(Command c, Displayable s)
{
if (c == sendCmd)
{
System.out.println("hi i m near cmd action");
//Thread t= new Thread();
messagesend ms = new messagesend();
ms.start();
System.out.println("hi i m near cmd action 2");
}
else if (c == exit)
{
destroyApp(true);
notifyDestroyed();
}
}
public void pauseApp() {
}
public class messagesend extends Thread{
public MessageConnection mc;
public TextMessage tm;
public String msg;
public Message m;
public void run()
{

System.out.println("hi i m near cmd action 3");
try
{
mc = (MessageConnection) Connector.open("sms://:5000");
System.out.println("hi i m near cmd action 4");
//mc.setMessageListener(this);
tm = (TextMessage) mc.newMessage(MessageConnection.TEXT_MESSAGE);
System.out.println("hi i m near cmd action 5");
msg=txtmsg.getString();
System.out.println("hi i m near cmd action 6");
tm.setPayloadText(msg);
tm.setAddress("sms://:5000");
System.out.println("hi i m near cmd action 7");
System.out.println("Text message port"+tm.toString());
mc.send(tm);
System.out.println("hi i m near cmd action 8");
Alert a = new Alert("Success!","Message sent successfully", null,AlertType.INFO);
a.setTimeout(3000);
disp.setCurrent(a);
}
catch (Exception ex)
{
ex.printStackTrace();
Alert a=new Alert("Error" , "This Error Occured"+ex,null,AlertType.ERROR);
}
finally
{
if (mc != null)
{
try
{
mc.close();
}
catch (Exception e) {}
}
}
}
}
public void destroyApp(boolean unconditional) {
}
}
Reply With Quote

#2 Old Re: Sms sending through j2me.. - 2007-12-13, 10:15

Join Date: Aug 2003
Posts: 181
Location: South Africa
stevejanko
Offline
Regular Contributor
Hi

Your problem is the way you format your Connection i.e.

mc = (MessageConnection) Connector.open("sms://:5000"); and
tm.setAddress("sms://:5000");

the format should be sms://telephone number:port
Unless you want the recipient to receive the message on a specific port, leave the port out.

I have made changes to your code and tested it.

...
String addr="sms://" + phno.getString();
mc = (MessageConnection) Connector.open(addr);
System.out.println("hi i m near cmd action 4");
//mc.setMessageListener(this);
tm = (TextMessage) mc.newMessage(MessageConnection.TEXT_MESSAGE);
System.out.println("hi i m near cmd action 5");
msg=txtmsg.getString();
System.out.println("hi i m near cmd action 6");
tm.setPayloadText(msg);
tm.setAddress(addr);
System.out.println("hi i m near cmd action 7");
System.out.println("Text message port"+tm.toString());
mc.send(tm);
...

hope this helps

Regards
Steve
Reply With Quote

#3 Old Smile Re: Sms sending through j2me.. - 2007-12-14, 13:59

Join Date: Nov 2007
Posts: 5
shankar.vaval
Offline
Registered User
Hi stevejanko


Thanks for your help ! but its working only for nokia 60 series mobiles, in other words mobiles which support middlet applications like Nokia 6630, Samsung X 640 are able to recieve the messages but its not working for Nokia 1100, Nokia 6030
[Not recieving]
Please guide me with this ...i need to build the application which sends message to all handsets... please help me in this regard .. how to implement this or how to solve this problem...

Thanks & Regards
Shankar
Reply With Quote

#4 Old Re: Sms sending through j2me.. - 2007-12-14, 14:34

Join Date: Aug 2003
Posts: 181
Location: South Africa
stevejanko
Offline
Regular Contributor
Hi

Are you putting in a port number? i.e sms://0821231234:5000

where 5000 is the port number

Regards
Steve
Reply With Quote

#5 Old Re: Sms sending through j2me.. - 2007-12-17, 07:47

Join Date: Nov 2007
Posts: 5
shankar.vaval
Offline
Registered User
Dear Steve,
As u guided me, thats the way i have coded, but the lower end mobiles like nokia 1100,nokia 6030,nokia 3300 are not able to receiving messages.. You can see the following code...please help me in the regard...You are the only hope for me.

import javax.microedition.io.Connector;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.wireless.messaging.Message;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.MessageListener;
import javax.wireless.messaging.TextMessage;
import javax.wireless.messaging.*;

/**
* @author shankar.vaval
*/
public class SendOnly extends MIDlet implements CommandListener {
private Display disp;
private TextField textMesg;
private TextField dest;
private Command back;
private Command send;
private String serverPort;
public SendOnly()
{
disp = Display.getDisplay(this);
back = new Command("back",Command.BACK,2);
send = new Command("SEND",Command.OK,1);
serverPort = getAppProperty("SMS-Port");
}
public void startApp()
{
Form form = new Form ("Messaging");
textMesg = new TextField("Message","",160, TextField.ANY);
dest = new TextField("Phone No.", "",20, TextField.PHONENUMBER);
form.append( dest );
form.append( textMesg );
form.addCommand(send);
form.addCommand(back);
form.setCommandListener((CommandListener) this);
disp.setCurrent(form);
}
public void commandAction(Command command,Displayable screen)
{
if (command == back)
{
destroyApp(false);
notifyDestroyed();
}
else if (command == send)
{
try
{
new Thread(new senderer()).start();
}
catch (Exception e)
{
System.out.print("Error in start");
e.printStackTrace();
}
}
}

public class senderer implements Runnable
{
public void run ()
{
try
{
String addr = "sms://"+dest.getString()+":5000";
MessageConnection conn = (MessageConnection) Connector.open(addr);
TextMessage msg = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE);
msg.setPayloadText(textMesg.getString());
conn.send(msg);
Alert a = new Alert("Success!","Message sent successfully", null,AlertType.INFO);
a.setTimeout(3000);
disp.setCurrent(a);
conn.close();
}
catch (Exception e)
{
System.out.println("Error in sending");
e.printStackTrace ();
}
}
}
public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}
}
Reply With Quote

#6 Old Re: Sms sending through j2me.. - 2007-12-17, 12:19

Join Date: Aug 2003
Posts: 181
Location: South Africa
stevejanko
Offline
Regular Contributor
Hi

The problem is in the line-
String addr = "sms://"+dest.getString()+":5000";

As you said it did not work for lower end phones (i.e phones that do not support Java). I think the reason is that if you send to a port, lower end phones do not know what to do with the port number (if I remember correctly - if you take the SIM out of a phone that you have sent a message to and put it in a phone that knows what to do with the port, you will receive all the messages sent to the origional lower end phone).

remove the port number (as in the origional change I made for you)
i.e change the above line to read -

String addr = "sms://"+dest.getString();

and all phones will receive your SMS.

Please let me know if the above works for you.

Regards
Steve
Reply With Quote

#7 Old Unhappy Re: Sms sending through j2me.. - 2007-12-28, 07:25

Join Date: Nov 2007
Posts: 5
shankar.vaval
Offline
Registered User
HI Steve,
I was on leave, i haven't seen ur reply sorry for that.. the same as u mentioned i have did, but still it is not working(ie. not sending messages to all nokia phones).. i m trying hard to check it out...please inform me if u can,now i m working on cell info display through j2me application (i.e i want to get location string cell info display message from j2me application..) DO u have any idea regarding this,please do help....
Reply With Quote

#8 Old Re: Sms sending through j2me.. - 2008-01-18, 15:50

Join Date: Aug 2003
Posts: 181
Location: South Africa
stevejanko
Offline
Regular Contributor
Hi

Sorry, It was my turn to be on leave.

Regarding Cell location, I have not ever used JSR179, so unfortunately I can not help you with that question.

As to the SMS problem, using the code below I could send from my N95 to a 1100 and the 1100 DID receive the SMS.

import javax.microedition.io.Connector;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.wireless.messaging.Message;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.MessageListener;
import javax.wireless.messaging.TextMessage;
import javax.wireless.messaging.*;

/**
* @author shankar.vaval
*/
public class SendOnly extends MIDlet implements CommandListener {
private Display disp;
private TextField textMesg;
private TextField dest;
private Command back;
private Command send;
private String serverPort;
public SendOnly()
{
disp = Display.getDisplay(this);
back = new Command("back",Command.BACK,2);
send = new Command("SEND",Command.OK,1);
serverPort = getAppProperty("SMS-Port");
}
public void startApp()
{
Form form = new Form ("Messaging");
textMesg = new TextField("Message","",160, TextField.ANY);
dest = new TextField("Phone No.", "",20, TextField.PHONENUMBER);
form.append( dest );
form.append( textMesg );
form.addCommand(send);
form.addCommand(back);
form.setCommandListener((CommandListener) this);
disp.setCurrent(form);
}
public void commandAction(Command command,Displayable screen)
{
if (command == back)
{
destroyApp(false);
notifyDestroyed();
}
else if (command == send)
{
try
{
new Thread(new senderer()).start();
}
catch (Exception e)
{
System.out.print("Error in start");
e.printStackTrace();
}
}
}

public class senderer implements Runnable
{
public void run ()
{
try
{
String addr = "sms://"+dest.getString();
MessageConnection conn = (MessageConnection) Connector.open(addr);
TextMessage msg = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE);
msg.setPayloadText(textMesg.getString());
conn.send(msg);
Alert a = new Alert("Success!","Message sent successfully", null,AlertType.INFO);
a.setTimeout(3000);
disp.setCurrent(a);
conn.close();
}
catch (Exception e)
{
System.out.println("Error in sending");
e.printStackTrace ();
}
}
}
public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}
}

Hope it helps

Regards
Steve
Reply With Quote

#9 Old Smile Sms sending through j2me.. - 2008-01-21, 07:54

Join Date: Jan 2008
Posts: 16
meghaarya
Offline
Registered User
hi

I have made application that send sms using WMA API.I just want to know whether is it possible to send sms from one mobile to another without making use of WMA.if so then how cud we do this.

Thanks in advance.
Reply With Quote

#10 Old Re: Sms sending through j2me.. - 2008-01-21, 08:08

Join Date: Aug 2003
Posts: 181
Location: South Africa
stevejanko
Offline
Regular Contributor
Quote:
Originally Posted by meghaarya View Post
hi

I have made application that send sms using WMA API.I just want to know whether is it possible to send sms from one mobile to another without making use of WMA.if so then how cud we do this.

Thanks in advance.
Sorry the only way I know how to send an SMS using J2ME is as per the above example (that does not mean that there are not other methods)

Regards
Steve
Reply With Quote

#11 Old Re: Sms sending through j2me.. - 2008-01-21, 09:37

Join Date: Apr 2007
Posts: 1,757
Tiger79's Avatar
Tiger79
Offline
Forum Nokia Champion
Btw, maybe this is a little off-topic but regaridng JSR179 and abtaining cell-info through it : thats unfortunately not possible...
Reply With Quote

#12 Old Re: Sms sending through j2me.. - 2008-03-03, 02:48

Join Date: Feb 2008
Posts: 13
rakesh.hcu@gmail.com
Offline
Registered User
hi i m new to j2me and i m trying to developing Sms sending utility, i im using following code and trying to send sms from pc(Computer),but it is giving following error.

Error
java.lang.IllegalArgumentException: No line matching interface Clip supporting format PCM_SIGNED 11025.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian is supported.

Code:

import javax.microedition.io.Connector;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.wireless.messaging.Message;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.MessageListener;
import javax.wireless.messaging.TextMessage;
import javax.wireless.messaging.*;


public class SendOnly extends MIDlet implements CommandListener
{
private Display disp;
private TextField textMesg;
private TextField dest;
private Command back;
private Command send;
private String serverPort;
public SendOnly()
{
disp = Display.getDisplay(this);
back = new Command("back", Command.BACK, 2);
send = new Command("SEND", Command.OK, 1);
// serverPort = getAppProperty("SMS-Port");
}
public void startApp()
{
Form form = new Form("Messaging");
textMesg = new TextField("Message", "", 160, TextField.ANY);
dest = new TextField("Phone No.", "", 20, TextField.PHONENUMBER);
form.append(dest);
form.append(textMesg);
form.addCommand(send);
form.addCommand(back);
// form.setCommandListener(this);
form.setCommandListener((CommandListener)this);
disp.setCurrent(form);
}
public void commandAction(Command command, Displayable screen)
{
System.out.println("check1");
if (command == back)
{
System.out.println("check2");
destroyApp(false);
notifyDestroyed();
}
else if (command == send)
{
try
{
System.out.println("check3");
new Thread(new senderer()).start();
System.out.println("check5");
}
catch (Exception e)
{
System.out.print("Error in start");
e.printStackTrace();
}
}
}

public class senderer implements Runnable
{//System.out.println("After run");
public void run()
{
try
{
System.out.println("check4");
//String addr = "sms://" + dest.getString();
String addr = "sms://9440793634";
MessageConnection conn = (MessageConnection)Connector.open(addr);
TextMessage msg = (TextMessage)conn.newMessage(MessageConnection.TEXT_MESSAGE);
msg.setPayloadText(textMesg.getString());
System.out.println("just before sending message");
conn.send(msg);
System.out.println("After sending message");
Alert a = new Alert("Success!", "Message sent successfully", null, AlertType.INFO);
//System.out.println("\n");
System.out.println("hia");
a.setTimeout(3000);
System.out.println("after timeout");
disp.setCurrent(a);
System.out.println("after display");
conn.close();
System.out.println("After close");
}
catch (Exception e)
{
System.out.println("Error in sending");
e.printStackTrace();
}
System.out.println("After Exception");
}
//System.out.println("After run");
}
public void pauseApp()
{
System.out.println("Inside pauseApp");
}

public void destroyApp(boolean unconditional)
{
System.out.println("Inside destroyApp");
}
}


I am trying for this long hard but i am not able to find out solution, so please u help me .
Is there requirement of any special software.
It is urgent for me and I have little time.

thanks in advance.

Email- rakesh.hcu@gmail.com
Reply With Quote

#13 Old Re: Sms sending through j2me.. - 2008-03-03, 09:01

Join Date: Aug 2003
Posts: 181
Location: South Africa
stevejanko
Offline
Regular Contributor
Hi

I took your code (as is) and using netbeans 5.5 I compiled it, then I loaded the .jar file to a N95 and it worked properly (The number hardcoded into your source should have received an SMS).

What are you using to send the SMS from the PC?

Regards
Steve
Reply With Quote

#14 Old Re: Sms sending through j2me.. - 2008-03-03, 12:41

Join Date: Feb 2008
Posts: 53
vin7805
Offline
Regular Contributor
Hi..

I am also working on sms sending application..as i have tested this code it working fine. with all nokia phones.

can you help me to write a inbuilt message in the code.

and the application should only ask for number when we run the application.

is it possible with the above code.

Thanks
vineet
Reply With Quote

#15 Old Re: Sms sending through j2me.. - 2008-03-03, 14:17

Join Date: Aug 2003
Posts: 181
Location: South Africa
stevejanko
Offline
Regular Contributor
Quote:
Originally Posted by vin7805 View Post
Hi..

I am also working on sms sending application..as i have tested this code it working fine. with all nokia phones.

can you help me to write a inbuilt message in the code.

and the application should only ask for number when we run the application.

is it possible with the above code.

Thanks
vineet
Hi

If I understand your question correctly, the answer is yes

Simply replace the Line:

msg.setPayloadText(textMesg.getString());

with msg.setPayloadText("Your String");

Regards
Steve
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Receiving SMS by J2ME Midlet on 3410 mlamb Mobile Java General 6 2009-03-24 14:13
6310i 4.80 bugs + few words about Nokia politics + other feedback mwiacek General Messaging 2 2007-11-10 14:19
nokia 30: no response on sending SMS itsmeamar Nokia M2M 2 2003-05-26 11:20
3410 J2ME Problem Sending SMS on Server connection keithmarsh Mobile Java General 1 2002-09-06 09:35
Sending and receiving SMS messages from J2ME application nkn_motoko Mobile Java General 1 2001-11-06 21:34

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia