Skip to main content

problem of receiving sms using new GUI builder

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
1 reply [Last post]
rashmitasahoo
Offline
Joined: 2010-10-26
Points: 0

Hi All,

I will create an application that will send an text msg on specific port using new Latest LWUIT GUI Builder. The send msg on specific port code will be return into the StateMachine.java class to send the sms but where i can write sms receive code to receiving the sms through server and i want to wait for 2 minute for receiving sms. In between 2 minutes if u got the receiving sms then it will show that msg in the dialog box and then go to next form otherwise your process will be terminate and you should go to send sms process.

I have my code as like this:

try
{
String address = "sms://1236587485:5000";
smsconn = (MessageConnection) Connector.open(address);
TextMessage txtmessage = (TextMessage) smsconn.newMessage(MessageConnection.TEXT_MESSAGE);
txtmessage.setAddress(address);
txtmessage.setPayloadText("Hello World! I am an Indian.");
Thread.sleep(800);
try {
smsconn.send(txtmessage);
} catch (Exception ex) {
ex.printStackTrace();
}
smsconn.close();
} catch (Exception ex) {
ex.printStackTrace();
}
SMSReceive receive=new SMSReceive();

public class SMSReceive {
/**
* Initialize the MIDlet with the current display object and
* graphical components.
*/
public SMSReceive() {

new Thread(new Runnable() {

public void run()
{
try
{
MessageConnection conn = (MessageConnection) Connector.open("sms://:5000");
//set message listener
conn.setMessageListener(
new MessageListener() {
public void notifyIncomingMessage(MessageConnection conn) {
try {
Message msg = conn.receive();
//do whatever you want with the message
Dialog d=new Dialog("From:"+msg.getAddress());
if(msg instanceof TextMessage) {
TextMessage tmsg = (TextMessage) msg;
System.out.println(tmsg.getPayloadText());
d.addComponent(new Label(tmsg.getPayloadText()));
}
d.addCommand(new Command("Ok"));
d.showPacked(BorderLayout.CENTER, false);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}).start();
}
}

I have an error like connection is already open and error in connector.open(). Please help me how to and where i will write receive sms code and give me sample code for receiving sms that i will receive the sms of corresponding sending sms code return in above. Please send me as soon as possible earlier.

Advance Thank you and sorry for my english.

Rashmita Sahoo

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
vprise
Offline
Joined: 2003-11-07
Points: 0

That error is unrelated to LWUIT, not sure whats the reason for it though.