Forum Stats

  • 3,814,249 Users
  • 2,258,850 Discussions
  • 7,892,636 Comments

Discussions

sending sms using java

850557
850557 Member Posts: 2
edited Aug 10, 2011 1:54AM in Mobile Services Architecture
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...

Answers

  • 881424
    881424 Member Posts: 1
    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);
    }
    }
    }
    }
    }
  • darrylburke
    darrylburke Member Posts: 18,007
    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
This discussion has been closed.