javax.wireless.messaging
Connector
objects, the same as any other communication
"sms://+1234567:5432"
for telephone number 1234567
"sms://:5432"
Send a message by
String address = "sms://+1234567:5432";
String msg = "Hello";
MessageConnection smsconn =
(MessageConnection) Connector.open(address);
TextMessage txtmessage = (TextMessage)smsconn.newMessage(
MessageConnection.TEXT_MESSAGE);
txtmessage.setPayloadText(msg);
smsconn.send(txtmessage)
try {
String addr = "sms://:5432";
MessageConnection conn = (MessageConnection) Connector.open(addr);
Message msg = null;
while (someExitCondition) {
// wait for incoming messages
msg = conn.receive(); // received a message
if (msg instanceof TextMessage) {
TextMessage tmsg = (TextMessage) msg;
String receivedText = tmsg.getPayloadText();
// respond with the same text with Received:
// inserted in the beginning
tmsg.setPayloadText("Received: " + receivedText);
// Note that the recipient address in the message is
// already correct as we are reusing the same object
conn.send(tmsg);
} else {
// Received message was not a text message, but e.g. binary ...
}
}
} catch (Exception e) {
...
}
emulator -Dwma.client.phoneNumber=1234567 ...