why are u using the port in ur code BTW I dont know what you have done in ur code here is simple class to send sms plz modify it to suit ur requirement
Class for sms screen
PHP Code:
public class Sms extends Form implements CommandListener
{
private Command sendCommand = new Command("Send", Command.EXIT, 1);
private Command backCommand = new Command("Back", Command.OK, 2);
private TextField mobile, smsTemplate;
String number, message;
/** Creates a new instance of Sms */
public Sms(/*Setting settingMagicTrack midlet*/)
{
super("Send SMS");
mobile = new TextField("Recipient No.", "", 13, TextField.PHONENUMBER);
mobile.setLayout(TextField.LAYOUT_EXPAND);
message="hello";
smsTemplate = new TextField("SMS Text", message, 1000, TextField.ANY);
smsTemplate.setLayout(TextField.LAYOUT_VEXPAND);
append(mobile);
append(smsTemplate);
addCommand(sendCommand);
addCommand(backCommand);
setCommandListener(this);
}
public boolean getValues()
{
number = mobile.getString();
message = smsTemplate.getString();
if(number.length() == 0)
{
Alert alert=new Alert("Alert","Recipient No. can’t be blank",null,AlertType.INFO);
alert.setTimeout(Alert.FOREVER);
Main.getInstance().showDisplayable(alert);
return false;
}
else if(number.length() < 10)
{
Alert alert=new Alert("Alert","Invalid Number",null,AlertType.INFO);
alert.setTimeout(Alert.FOREVER);
Main.getInstance().showDisplayable(alert);
return false;
}
return true;
}
public void commandAction(Command command, Displayable displayable)
{
if(command == backCommand)
{
//midlet.mainScreen.loadMap();
Main.getInstance().showGPSDisplayable();
}
else if(command == sendCommand)
{
try
{
if(getValues())
{
send sms1 = new send(number, message, Main.getInstance());
}
}
catch(Exception e)
{
DataBaseStore.getInstance().writeToLog("14#: "+e.toString());
}
}
}
}
Class for sending sms
PHP Code:
class send implements Runnable
{
private String number , message;
Thread t = new Thread(this);
private Main midlet;
public send(String number, String message, Main midlet)
{
this.number = number;
this.message = message;
this.midlet = midlet;
t.start();
}
public void sendMessage() throws IOException
{
MessageConnection conn=null;
// boolean result = true;
try {
//sets address to send message
String addr = "sms://"+number;
System.out.println(addr);
// opens connection
conn = (MessageConnection) Connector.open(addr);
// prepares text message
TextMessage msg = (TextMessage)conn.newMessage(MessageConnection.TEXT_MESSAGE);
//set text
msg.setPayloadText(message);
// send message
conn.send(msg);
Alert alert=new Alert("Sent","Sms has been sent",null,AlertType.INFO);
alert.setTimeout(Alert.FOREVER);
//alert.setString(se.toString());
midlet.display.setCurrent(alert);
//confirm.
}
catch (SecurityException se)
{
DataBaseStore.getInstance().writeToLog("89#: "+se.toString());
}
catch (Exception e)
{
DataBaseStore.getInstance().writeToLog("90#: "+e.toString());
}
finally
{
try
{
conn.close();
}
catch(Exception e)
{
DataBaseStore.getInstance().writeToLog("15#: "+e.toString());
}
}
// return result;
}
public void run()
{
try
{
sendMessage();
}
catch (IOException ex)
{
ex.printStackTrace();
DataBaseStore.getInstance().writeToLog("91#: "+ex.toString());
}
}
}
Note both class are interlinked so used in conjunction