Writing MIDlet for SMS - IV

11 April 2008

I will present the run method in this post.

Do remember that we are writing a multi threaded SMS MIDLet. The MIDLet signature reads like:

public class SMSReceive extends MIDlet
implements CommandListener, Runnable, MessageListener {
...
}

Lets define the run method:

public void run() {
 
try {
msg = smsconn.receive();
if (msg != null) {
senderAddress = msg.getAddress();
content.setTitle("From: " + senderAddress);
if (msg instanceof TextMessage) {
content.setString(((TextMessage)msg).getPayloadText());
} else {
StringBuffer buf = new StringBuffer();
byte[] data = ((BinaryMessage)msg).getPayloadData();
for (int i = 0; i < data.length; i++) {
int intData = (int)data & 0xFF;
if (intData < 0x10) {
buf.append("0");
}
buf.append(Integer.toHexString(intData));
buf.append(' ');
}
content.setString(buf.toString());
}
content.addCommand(replyCommand);
display.setCurrent(content);
}
} catch (IOException e) {
 e.printStackTrace();
}
}

The method is used to read the SMS message. If the message is a text message then things are simple. In the other case we have to read the message in a byte array.

del.icio.us:Writing MIDlet for SMS - IV  digg:Writing MIDlet for SMS - IV  spurl:Writing MIDlet for SMS - IV  wists:Writing MIDlet for SMS - IV  simpy:Writing MIDlet for SMS - IV  newsvine:Writing MIDlet for SMS - IV  blinklist:Writing MIDlet for SMS - IV  furl:Writing MIDlet for SMS - IV  reddit:Writing MIDlet for SMS - IV  fark:Writing MIDlet for SMS - IV  blogmarks:Writing MIDlet for SMS - IV  Y!:Writing MIDlet for SMS - IV  smarking:Writing MIDlet for SMS - IV  magnolia:Writing MIDlet for SMS - IV  segnalo:Writing MIDlet for SMS - IV  gifttagging:Writing MIDlet for SMS - IV

Top Of Page | Trackback

If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.

It will look like this: Writing MIDlet for SMS - IV

Leave a Reply