×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    4

    Sending sms within midlet???

    Hello,
    i would like to know if it is possible to send sms's from a midlet application??? i think so as i read the answers posted but apparently not on every phone...
    Which ones do support this possibility and where can i find informations related to it please(eg: classes, examples...)???
    Thanks in advance for your support.

  2. #2
    Regular Contributor
    Join Date
    Mar 2003
    Location
    Rennes, France
    Posts
    50

    RE: Sending sms within midlet???

    Hi Maxims,

    Actually you can send SMS with only the Nokia 3410. You must use the "Nokia SMS API" that you will find on Nokia's web site(http://www.forum.nokia.com/main/1,35452,1_0_10_30,00.html). Note that you will only find the API, but not the code. You have to write it yourself, but as this is composed of interfaces it's not complicated... (the code is included with the post). The SMS API has also been announced to run on the Nokia 3650. The API running in the 3410, called Nokia SMS API is not standardized. You can see that interfaces belong to the package com.nokia.mid.messaging. But this API is really close to the Wireless Messaging API created by the JSR 120 expert group (nokia belongs to that JSR so that explains why the 2 API are so close). Globally, you just have to change the name of the package to javax.wireless.messaging and the program you wrote for the 3410 should also run on the 3650. There might be some differences. I don't exactly know because I haven't had time yet to look at it in deep.

    I hope this help.

    Below you will find an example which runs on the 3410 with at least the firmware v4.09.

    The API, is composed of 5 interfaces so you can write the code by yourself and put it in the good package.
    For that, you'll need 5 different files:

    //file1: BinaryMessage.java
    package com.nokia.mid.messaging;

    public interface BinaryMessage extends Message {
    byte[] getPayloadData();

    void setPayloadData(byte[] data);
    }

    //file2: Message.java
    package com.nokia.mid.messaging;

    public interface Message {
    String getAddress();

    void setAddress(String addr);

    java.util.Date getTimestamp();
    }

    //file3: MessageConnection.java
    package com.nokia.mid.messaging;

    public interface MessageConnection extends javax.microedition.io.Connection {
    int TEXT_MESSAGE = 1;
    int BINARY_MESSAGE = 2;

    Message newMessage(int type);

    Message newMessage(int type, String address);

    void send(Message msg) throws java.io.IOException, java.io.InterruptedIOException;

    Message receive() throws java.io.IOException, java.io.InterruptedIOException;

    void registerMessageListener(MessageListener l) throws java.io.IOException;
    }

    //file4: MessageListener.java
    package com.nokia.mid.messaging;

    public interface MessageListener {
    void notifyIncomingMessage(MessageConnection conn);
    }

    //file5: TextMessage.java
    package com.nokia.mid.messaging;

    public interface TextMessage extends Message {
    String getPayloadText();

    void setPayloadText(String str);
    }

    After, you can test the API with that program. Some version of the phone doesn't work. This program runs with the version v4.09

    /*
    * SendSMS.java
    *
    * Created on 12. elokuuta 2002, 13:54
    */

    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.io.*;

    import com.nokia.mid.messaging.MessageConnection;
    import com.nokia.mid.messaging.TextMessage;

    /**
    *
    * @author fred
    * @version
    */
    public class SendSMS extends MIDlet implements CommandListener {

    private Form form;

    private Display display;

    private Command exit;
    private Command ok;

    public void startApp() {
    display = Display.getDisplay( this );
    form = new Form("Send message"
    form.append("Do you want to send the message?"
    ok = new Command("Send",Command.OK,2);
    exit = new Command("Exit",Command.EXIT,1);
    form.addCommand(ok);
    form.addCommand(exit);
    form.setCommandListener( this );
    display.setCurrent( form);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void send() {
    String gsm_number = "041123456";

    try {

    String addr = "com.nokia.sms://"+gsm_number;

    MessageConnection conn = (MessageConnection)Connector.open(addr);

    TextMessage msg = (TextMessage)conn.newMessage(MessageConnection.TEXT_MESSAGE);

    msg.setPayloadText( "This is a test" );

    conn.send(msg);

    form = new Form("Send message"
    form.append("Message sent"
    exit = new Command("Exit",Command.EXIT,1);
    form.addCommand(exit);
    form.setCommandListener( this );
    display.setCurrent( form );


    }catch(Exception e) {
    form = new Form("Error"
    form.append("Some error"
    exit = new Command("Exit",Command.EXIT,1);
    form.addCommand(exit);
    form.setCommandListener( this );
    display.setCurrent( form );
    }

    }

    public void commandAction(Command command, Displayable displayable) {
    if(command == ok){
    send();
    }
    if(command == exit){
    destroyApp( true );
    notifyDestroyed();
    }
    }

    }

    Frdric

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    5

    Re: Sending sms within midlet???

    When i insert "import javax.wireless.messaging.*;" error return "the import javax.wireless.messaging never used". Help me?

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    3

    Lightbulb Re: Sending sms within midlet???

    Quote Originally Posted by vu_dinh
    When i insert "import javax.wireless.messaging.*;" error return "the import javax.wireless.messaging never used". Help me?
    I dont think the above import statement is necessary bcuz any handset that supports WMA should be able to send a message thru midlet.you just need to give the send and receive permissions
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
    import javax.wireless.messaging.*;



    public class SMSWork extends Canvas implements Runnable
    {
    Form f = null;
    MessageConnection mconn;
    TextMessage mesg ;
    private static final int LSK = -6;
    private static final int RSK = -7;
    static final int UP_PRESSED = -1;
    static final int DOWN_PRESSED = -2;
    private static final int LEFT_PRESSED = -3;
    private static final int RIGHT_PRESSED = -4;
    Thread t= null;

    public SMSWork()
    {

    }
    public void openConnection()
    {
    try
    {
    mconn = (MessageConnection) Connector.open("sms://:2622");
    mesg = (TextMessage) mconn.newMessage(MessageConnection.TEXT_MESSAGE);
    mesg.setPayloadText("Hello World");
    mesg.setAddress("sms://+9867090375:123400");
    }
    catch(Exception e)
    {
    System.out.println("Exception in connection");
    }
    }

    public void sendSms()
    {
    try
    {
    mconn.send(mesg);

    }
    catch(Exception e)
    {
    System.out.println(e.getMessage());
    }
    }

    protected void paint(Graphics g) {
    // TODO Auto-generated method stub
    g.setColor(0xffffff);
    g.fillRect(0,0,176,220);
    g.setColor(0);
    g.drawString("Send",100,180,Graphics.TOP|Graphics.LEFT);
    }

    protected void keyPressed(int key)
    {
    if(key == RSK)
    {
    t= new Thread(this);
    t.start();
    }
    }
    public void run() {
    // TODO Auto-generated method stub
    sendSms();
    }
    }
    this should help
    All i want to do is code, code and code...
    phew!

Posting Permissions

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