This discussion is archived
2 Replies Latest reply: Aug 9, 2011 10:54 PM by DarrylBurke RSS

sending sms using java

850557 Newbie
Currently Being Moderated
Hello all! i am doing one web application project in j2ee in that i need to set sms facility using java program and i have no idea on that so i am kindly requesting you to help me on that...


thanks
vinoth...
  • 1. Re: sending sms using java
    881424 Newbie
    Currently Being Moderated
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.MIDlet;
    import javax.wireless.messaging.*;
    public class SendSms extends MIDlet implements CommandListener {
    Display display;
    private TextField toWhom;
    private TextField message;
    private Alert alert;
    private Command send,exit;
    MessageConnection clientConn;
    private Form compose;
    public SendSms() {
    display=Display.getDisplay(this);
    compose=new Form("Compose Message");
    toWhom=new TextField("To","",10,TextField.PHONENUMBER);
    message=new TextField("Message","",600,TextField.ANY);
    send=new Command("Send",Command.BACK,0);
    exit=new Command("Exit",Command.SCREEN,5);
    compose.append(toWhom);
    compose.append(message);
    compose.addCommand(send);
    compose.addCommand(exit);
    compose.setCommandListener(this);
    }
    public void startApp() {
    display.setCurrent(compose);
    }
    public void pauseApp() {
    }
    public void destroyApp(boolean unconditional) {
    notifyDestroyed();
    }
    public void commandAction(Command cmd,Displayable disp) {
    if(cmd==exit) {
    destroyApp(false);
    }
    if(cmd==send) {
    String mno=toWhom.getString();
    String msg=message.getString();
    if(mno.equals("")) {
    alert = new Alert("Alert");
    alert.setString("Enter Mobile Number!!!");
    alert.setTimeout(2000);
    display.setCurrent(alert);
    }
    else {
    try {
    clientConn=(MessageConnection)Connector.open("sms://"+mno);
    }
    catch(Exception e) {
    alert = new Alert("Alert");
    alert.setString("Unable to connect to Station because of network problem");
    alert.setTimeout(2000);
    display.setCurrent(alert);
    }
    try {
    TextMessage textmessage = (TextMessage) clientConn.newMessage(MessageConnection.TEXT_MESSAGE);
    textmessage.setAddress("sms://"+mno);
    textmessage.setPayloadText(msg);
    clientConn.send(textmessage);
    }
    catch(Exception e)
    {
    Alert alert=new Alert("Alert","",null,AlertType.INFO);
    alert.setTimeout(Alert.FOREVER);
    alert.setString("Unable to send");
    display.setCurrent(alert);
    }
    }
    }
    }
    }
  • 2. Re: sending sms using java
    DarrylBurke Guru Moderator
    Currently Being Moderated
    Moderator advice: Please read the announcements at the top of the forum listing and the forums FAQ linked from every page. They are there for a purpose.

    Then edit your post and format the code correctly.

    db

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points