×

Discussion Board

Results 1 to 6 of 6

Thread: receive sms

  1. #1
    Regular Contributor
    Join Date
    Jul 2009
    Posts
    51

    receive sms

    I tried an example to receive sms. The program throwed an exception. Same thing happened for the example in SMSReceive under WMADemo. It says
    java/lang/IllegalArgumentException Port number format error
    Last edited by csckid; 2010-07-25 at 19:08.

  2. #2
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: receive sms

    I will appreciate if you could let us know the exact line of code where you are trying to open the SMS connection.
    I suspect that you forget to mention the port number onside the jad attributes, since that code reads the same from the Jad file.Kindly add the attributes and check the same.I am sure that this issue will be fixed.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    15

    Re: receive sms

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package newpackage;

    import java.io.IOException;

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

    import javax.wireless.messaging.*;


    /**
    * An example MIDlet displays text from an SMS MessageConnection
    * BY DEEPAK KINNI
    */
    public class SMSReceive extends MIDlet implements CommandListener, Runnable, MessageListener {
    Command exitCommand = new Command("Exit", Command.EXIT, 2);
    Alert content;
    Display display;
    Thread thread;
    String[] connections;
    boolean done;
    String smsPort;
    MessageConnection smsconn;
    Message msg;
    String senderAddress;
    Displayable resumeScreen;
    String txtInHex;
    byte [] txtInByte;
    int len;

    public SMSReceive() {
    smsPort = getAppProperty("SMS-Port");

    display = Display.getDisplay(this);

    content = new Alert("SMS Receive");
    content.setTimeout(Alert.FOREVER);
    content.addCommand(exitCommand);
    content.setCommandListener(this);
    content.setString("Receiving...");


    resumeScreen = content;
    }
    public void startApp() {
    String smsConnection = "sms://:" + smsPort;

    if (smsconn == null) {
    try {
    smsconn = (MessageConnection)Connector.open(smsConnection);
    smsconn.setMessageListener(this);
    } catch (IOException ioe) {
    ioe.printStackTrace();
    }
    }
    connections = PushRegistry.listConnections(true);

    if ((connections == null) || (connections.length == 0)) {
    content.setString("Waiting for SMS on port " + smsPort + "...");
    }

    done = false;
    thread = new Thread(this);
    thread.start();

    display.setCurrent(resumeScreen);
    }
    public void notifyIncomingMessage(MessageConnection conn) {
    if (thread == null) {
    done = false;
    thread = new Thread(this);
    thread.start();
    }
    }
    public void run() {
    try {
    msg = smsconn.receive();

    if (msg != null) {
    senderAddress = msg.getAddress();
    content.setTitle("From: " + senderAddress);
    if (msg instanceof TextMessage) {
    txtInHex=((TextMessage)msg).getPayloadText();
    }else {
    StringBuffer buf = new StringBuffer();
    byte[] data = ((BinaryMessage)msg).getPayloadData();

    for (int i = 0; i < data.length; i++) {
    int intData = (int)data[i] & 0xFF;

    if (intData < 0x10) {
    buf.append("0");
    }

    buf.append(Integer.toHexString(intData));
    //buf.append(' ');
    }

    txtInHex=(buf.toString());
    }



    txtInByte = new byte [txtInHex.length() / 2];
    int j = 0;
    for (int i = 0; i < txtInHex.length()-2; i += 2)
    {
    txtInByte[j++] = Byte.parseByte(txtInHex.substring(i,i+2),16);
    }
    String txt = new String(txtInByte);
    content.setString(txt);
    display.setCurrent(content);
    }
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    public void pauseApp() {
    done = true;
    thread = null;
    resumeScreen = display.getCurrent();
    }
    public void destroyApp(boolean unconditional) {
    done = true;
    thread = null;

    if (smsconn != null) {
    try {
    smsconn.close();
    } catch (IOException e) {
    }
    }
    }

    public void commandAction(Command c, Displayable s) {
    try {
    if ((c == exitCommand) || (c == Alert.DISMISS_COMMAND)) {
    destroyApp(false);
    notifyDestroyed();
    }
    } catch (Exception ex) {
    ex.printStackTrace();
    }
    }

    }

  4. #4
    Registered User
    Join Date
    Jan 2010
    Posts
    15

    Re: receive sms

    Thats the program!!!...BTW the program accepts HEX data nd den converts it into ASCII....my assignment required me to do that!!
    anyways apart from jus typing in the code you have to also go the Application Descriptor option and insert specific PORT NUMBER into the field,
    Then go to Push Registry option also register there...

    the logic here is:see when you receive a message it has two address:the mobile number,port number...so what happens is you usually
    specify the mobile no. when it reaches the cell it by default goes to the INBOX if you also specify the port number what will happen is as soon as the
    message is received it invokes the App and uses your Apps default way of showing the incoming message!!
    I ve written all these things coz you MIGHT face all these problems wen go ahead!...

  5. #5
    Regular Contributor
    Join Date
    Jul 2009
    Posts
    51

    Re: receive sms

    Does this works in all cell phone?

  6. #6
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: receive sms

    Quote Originally Posted by csckid View Post
    Does this works in all cell phone?
    yes, it should work on all MIDP 2.0 devices.
    Thanks,
    Ekta

Similar Threads

  1. Replies: 9
    Last Post: 2010-08-03, 07:03
  2. Receive inbox sms to j2me midlet with nokia sms api?
    By Carloswaldo in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2009-10-26, 08:31
  3. How to receive a SMS on port 0 using a MIDlet without letting the SMS go to
    By ravidiwakar.25@gmail.com in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2008-09-15, 08:40
  4. Replies: 9
    Last Post: 2004-03-24, 07:53
  5. Replies: 1
    Last Post: 2002-07-10, 09:51

Posting Permissions

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