How to send SMS in J2ME?

Pusu will report the motion several ways. Via SMS, MMS, Bluetooth. The simplest one is SMS so firstly we do SMS to report. With WMA, sending SMS in J2ME very simple. A generic MessageConnection opens the reporting way to connect the desired user about the situation. The receiving section comes with some obstacles. Since we want our Motion Detector controlled by simple SMS which is sent by an ordinary mobile phone message, the application should access the SMS messages targetted towards it. But an application running on the mobile phone is listenning to the messages which is specified to its port number. Unfortunately, at the time being we could not find a decent way to specify an SMS message which is not only defines the phone number but also the port number of the application. We will work on that matter. Now we explain the SMS reporting of the system.

WMA is supported through javax.microedition.messaging package, which includes the interfaces below:

Message: The basic interface for a message. Commonly needed methods are defined such as the ability to get or set the address associated with the message and to retrieve the timestamp of when the message was sent.
BinaryMessage: Extends the Message interface, allowing an application to extract the binary payload of the message.
TextMessage: Extends the Message interface, allowing an application to extract the ASCII payload of the message.
MessageConnection: Supports the functionary for sending and receiving messages based on the underlying protocol.
MessageListener: Allows classes that implement this interface to register with an instance of MessageConnection to be notified when a new message is received.

Sending SMS with WMA (Wireless Messaging API) is done as below code: 

   1: //destination is the user specified mobile phone number


   2: // an example for destination = "+905335555555"


   3: String addr = "sms://" + destination;


   4: MessageConnection sender = null;


   5: try {


   6:     try {


   7:         //connection creation


   8:         sender = (MessageConnection) Connector.open(addr);


   9:         //message creation


  10:         TextMessage msg = (TextMessage) sender.newMessage(MessageConnection.TEXT_MESSAGE);


  11:         //message is load


  12:         msg.setPayloadText(message);


  13:         //send it


  14:         sender.send(msg);


  15:     } finally {


  16:         sender.close();


  17:     }


  18: } catch (Exception ex) {


  19:     //handle exception 


  20: }


No matter which protocol you are using, the messaging operations are nearly the same. There is a minor difference between SMS and CBS. SMS listens to a port where CBS listens to a channel.

Specific to Pusu, when the motion detection system detects a motion, the reporter class is invoked. Reporter class can have various implementations according to the user definition for reporting. The destination phone number is also defined by user. The message to be send is build by the application.

Originally posted in 2005.03.30 by Cahit Güngör - The Pusu Project Blog

J2ME Camera Speed Evaluation

Research Group Embedded Interaction has evaluated getting snapshot speed of the Nokia 6600 by J2ME code. This evaluation covers different encoding formats (PNG, BMP and JPEG) and resolution sizes (80x60, 160x120 and 200x150) with durations between one and ten seconds. The following tables show the results of the different simulations:

 
Format of the image: PNG

clip_image002

 

Format of the image: BMP

clip_image004

 

Format of the image: JPEG

clip_image006

byte[]jpegImageData=videoControl.getSnapshot (“encoding=jpeg&width=120&height=90”);

Above results are all involves the explicitly specified resolutions in their "getSnapshot" methods like above. What about a default resolution? (null value for diemnsions) The result is amazing. Performance increased by four times! (for ten minutes duration) The quality of the image remains same as before.


BMP and default resolution:

clip_image008

 

Originally posted by Orçun Dayıbaş in 2005.02.19 - The Pusu Project Blog

The Pusu Project

logo_wpOne of the main motivations of starting that blog is loss of my old one (hosted by the university that eagerly needed an extra 10 MB server space and deleted all "relatively old" accounts without any notice).


Anyways, as a software engineer, I always backup (and barely remember where to find ;) ) my works and development notes of the Pusu Project is no exception... I will -at least partially- repost them here as soon as possible



P.S.1: The expired URL of the Pusu Project development blog is http://web.cs.hacettepe.edu.tr/~b20021809/project/pusu

P.S.2: Pusu is the world's first 100% managed J2ME motion detection application (project has been completed in 2005).

P.S.3: I want to acknowledge my project colleague Cahit Güngör and project supervisor Kayhan İmre.