Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: developing a mobile application in j2me to send and receive message in sun java

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default developing a mobile application in j2me to send and receive message in sun java

    hey, i m developing a mobile application in which i need to send and recieve a message,any1 who can help me with its code .thanx in advance


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 286 Times in 225 Posts
    Blog Entries
    4

    Default Re: developing a mobile application in j2me to send and receive message in sun java

    Hello neha,

    Welcome to the Java Programming Forums.

    I know of two solutions you can try.

    WMA (Wireless Messaging API) is a wireless messaging api defined in MIDP 2.0. These apis are designed to handle text, binary and multipart messages. To make a connection, the application obtains an object implementing the MessageConnection from the Connector class by providing an URL connection string that identifies the address.
    /* Make a connection */
    public boolean connectSMSServer() 
    {
      try 
      {
        messageConnection messageConnection = 
          (MessageConnection)Connector.open("sms://:" + port);
        messageConnection.setMessageListener(this);
      }
      catch (Exception e) {
      }
    }
     
    /* Send text message */
    public void sendTextmessage(String address,String message) 
    {
      try 
      {
        //creates a new TextMessage
        TextMessage textMessage = (TextMessage)messageConnection.newMessage(
                MessageConnection.TEXT_MESSAGE, address);
        textMessage.setPayloadText(message);
        messageConnection.send(textMessage);
      } 
      catch (Exception e) {
      }
    }
     
    /* Recieve text message */
    public void receiveTextMessage() 
    {
      try 
      {
        Message message = messageConnection.receive();
        if (message instanceof TextMessage) 
        {
          TextMessage textMessage = (TextMessage)message;
        } 
        else 
        {
          //Message can be binary or multipart
        }                   
      } 
      catch (Exception e) {
      }
    }
     
    /* Notify Incoming Message */
    public synchronized void notifyIncomingMessage(MessageConnection conn) 
    {
      //notiy thread of incoming message
      synchronized (this)
      {
        notify();
      }
    }
     
    /* Close Connection */
    public void closeConnection() 
    {
      if (messageConnection != null) 
      {
        try 
        {
          messageConnection.setMessageListener(null);
          messageConnection.close();
        } 
        catch (Exception e) {
        }
        }
      }
    }

    WMAPI allows Java ME applications to access messaging functionalities, as sending and receiving SMS and MMS messages. This article explains how to use it to send a simple text message.
    public boolean sendSms(String number, String message){
        boolean result = true;
        try {
          //sets address to send message
          String addr = "sms://"+number;
          // opens connection
          MessageConnection conn = (MessageConnection) Connector.open(addr);
          // prepares text message
          TextMessage msg =
          (TextMessage)conn.newMessage(MessageConnection.TEXT_MESSAGE);
          //set text
          msg.setPayloadText(message);
          // send message
          conn.send(msg);
          conn.close();
        } catch (SecurityException se) {
            // probably the user has not allowed to send sms
            // you may want to handle this differently
            result = false;
        } catch (Exception e) {
            result = false;
        }
        return result;
      }

    How to Send Text SMS in Java ME - Forum Nokia Wiki

    I have limited experience with this so hopefully someone else here can help you move forward.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  3. #3
    Junior Member
    Join Date
    Mar 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: developing a mobile application in j2me to send and receive message in sun java

    i have already tried similar code..its not working..actualy i m making a project on security in mobile banking using steganography ..if ne 1 can help me with lil bit of its code..it ll b nice
    thanxx...

Similar Threads

  1. How to copy J2ME application to a mobile device
    By vishal21 in forum Java ME (Mobile Edition)
    Replies: 2
    Last Post: January 21st, 2012, 04:52 PM
  2. J2ME application not launching
    By vishal21 in forum Java ME (Mobile Edition)
    Replies: 0
    Last Post: November 22nd, 2010, 12:15 PM
  3. Need help in developing a clock application
    By sb.shiv in forum AWT / Java Swing
    Replies: 2
    Last Post: August 24th, 2010, 02:00 AM
  4. [SOLVED] Send and Receive Parameter
    By java_mein in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: May 14th, 2010, 02:22 PM
  5. how to send a message to receiver with if else statement
    By humdinger in forum Loops & Control Statements
    Replies: 10
    Last Post: December 4th, 2009, 09:56 AM

Tags for this Thread