FeaturesPluginsDocs & SupportCommunityPartners

NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Sending SMS (where is my mistake?)

 
Post new topic   Reply to topic    NetBeans Forums -> Java ME Users
View previous topic :: View next topic  
Author Message
Hesam



Joined: 06 Jun 2009
Posts: 3

PostPosted: Wed Oct 07, 2009 11:57 am    Post subject: Sending SMS (where is my mistake?) Reply with quote

hi friends,

I wrote this program but i see some errors that i can't understand it. if it's possible please check it and tell me where is the problem.

Code:

package Kamalan.com;


import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.Connector;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.TextMessage;
//import com.sun.midp.lcdui.CommandAccess;

public class AdvertiseSMS extends MIDlet implements CommandListener, Runnable
{
    private Command cmSend, cmExit;
    private TextBox tbMessage;

    public void pauseApp() {
    }

    public void destroyApp(boolean arg0) throws MIDletStateChangeException
    {
    }

    protected void startApp() throws MIDletStateChangeException
    {
        tbMessage = new TextBox("Message", "", 160, TextField.ANY);

        tbMessage.addCommand(cmSend = new Command("Send SMS", Command.OK, 1));
        tbMessage.addCommand(cmExit = new Command("Exit", Command.EXIT, 1));

        Display.getDisplay(this).setCurrent(tbMessage);
    }

    public void commandAction(Command c, Displayable d)
    {
   if(c == cmExit)
   {
            notifyDestroyed();
   }
   else if(c == cmSend)
   {
            new Thread(this).start();
   }
    }

    public void run()
    {
       boolean result = sendSms("0142329770", tbMessage.getString());
    }

    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)
   {
            result = false;
   }
   catch (Exception e)
   {
            result = false;
   }

   return result;

    }

}
Back to top
View user's profile Send private message
ch123



Joined: 09 Oct 2009
Posts: 1

PostPosted: Fri Oct 09, 2009 10:51 am    Post subject: Reply with quote

hi......

[URL="http://www.google.com"]http://www.google.com[/URL]
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Java ME Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB