Hi, I have created one source code which will help you to achieve this. Just use this to send sms using J2ME.
Code:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import com.siemens.mp.gsm.*;
public class smsone extends MIDlet implements CommandListener
{
private Form form;
private Command cmdOk,cmdExit;
private TextField msg;
public smsone()
{
}
public void startApp()
{
Display dis=Display.getDisplay(this);
form=new Form("Send SMS");
msg=new TextField("Dest No",null,160,2);
cmdOk=new Command("Send",Command.SCREEN,0);
cmdExit=new Command("Exit",Command.SCREEN,0);
form.append(msg);
form.addCommand(cmdOk);
form.addCommand(cmdExit);
form.setCommandListener(this);
disp.setCurrent(form);
}
public void pauseApp()
{
}
public void destroyApp(boolean b)
{
}
public void commandAction(Command c,Displayable dis)
{
if(c==cmdOk)
{
int rep=0;
String err_msg="";
try
{
SMS sms = new SMS();
String dest_no=msg.getString();
dest_no=dest_no.trim();
rep=sms.send(dest_no,"Sent from j2me");
msg.setLabel(""+rep);
}
catch(Exception e)
{
err_msg="error :"+e.getMessage();
System.out.println("error has occur:"+e);
e.printStackTrace();
}
}
else if(c==cmdExit)
{
notifyDestroyed();
}
}
}
Bookmarks