Thread: sms midlet
View Single Post
  #2 (permalink)  
Old 03-06-2008, 02:48 PM
sk_shadul sk_shadul is offline
Member
 
Join Date: Mar 2008
Posts: 5
sk_shadul is on a distinguished road
Hi Poonam,

You can send a text message with the following codes
MessageConnection conn =(MessageConnection) Connector.open("sms://5550001:1234");
TextMessage txtmessage = (TextMessage) conn.newMessage(
MessageConnection.TEXT_MESSAGE);
txtmessage.setPayloadText(msgString);
conn.send(txtmessage);

You can receive the message in two different ways:
1) Blocking the call
2) unblocking the call

First way:

conn = (MessageConnection) Connector.open("sms://5550001:1234");
msg = conn.receive(); // Blocking here
mSenderAddress = msg.getAddress(); // Get info from message
if (msg instanceof TextMessage) {
String msgReceived = ((TextMessage)msg).getPayloadText();
// Do something with the message here
} else if (msg instanceof BinaryMessage) {
byte [] msgReceived = ((BinaryMessage)msg).getPlayloadData();
// do something with the binary message here
}
}

Second Way:

For second way, register to the Interface like MessageListener


Regards,
sk_shadul
Reply With Quote