As I mentioned before, I am helping a client develop a cutting-edge J2ME solution. We all are learning J2ME as we go. No one among us is a J2ME expert by any means.
Today, we had to write code that sends SMS from a Midlet. It seemed pretty trivial. The API to send SMS has been part of J2ME for 2 years now. We expected no hiccups. In addition, we wanted to install the Midlet on the phone via OTA provisioning. Since, we do daily iterations, we have to deploy the fully tested Midlet on the real phone at the end of the day.
Now, just in one day, we learned so much. Had we just worked on one peice of functionality, and not attempted to complete the iteration, we would not have learned this much.
1. We first tried running the Midlet on Treo 600 with J9 JVM. However, all the SMS we tried sending failed. We decided to try another phone. It turns out, that there is some problem with J9 on Treo 600 and you cannot send SMS from the Midlet.
2. We tried installing the Midlet on Nokia 6230. When we tried installing the Midlet via OTA, the jad file opened in notepad. We learned that we had to set the mime type on the web server: “text/vnd.sun.j2me.app-descriptor” to jad. Once, we did this, the application manager started installing the Midlet, but the install failed, giving us an error message of “Invalid version”. We learned that, we had to set CLDC version to 1.0 and not 1.1 as set in the wireless toolkit.
3. Here we go again!. Now, with the CLDC version of 1.0, we tried installing the Midlet again. This time, we get an error of invalid file. We take all the resources out of the jar and try installing again. The install works. We could then run the midlet and send SMS.
4. We also learned that, the code to run SMS must be in a seperate thread to prevent blocking the GUI. Here is the sample code:
MessageConnection smsConnection = (MessageConnection) Connector.open(recipentAddress);
TextMessage messageToBeSent = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE);
msg.setPayloadText(messageContent);
msg.setAddress(recipentAddress);
conn.send(messageToBeSent);
conn.close();
recipentAddress has to be in plain sms://Phone Number format.
5. msg.setAddress(recipentAddress) in the code above is optional. However, if you do it, then the message will be sent to the address specified in the msg.setAddress and not Connector.open.
Tags: No Comments
0 responses so far ↓
There are no comments yet...Kick things off by filling out the form below.