Joke Collection Website - Blessing messages - J2ME watching SMS

J2ME watching SMS

J2me reads short messages through WMA

Import java.io.ioexception;

Import javax.microedition.midlet. *;

Import javax.microedition.io. *;

Import javax.wireless.messaging. *;

Common class example extension MIDlet implementation MessageListener {

Message connection messconn

int total = 0;

Boolean completion;

//Initial test setup and execution.

public void startApp() {

Try {

//Get our receive port connection.

Messconn = (message connection)

connector . open(" SMS://:6222 ");

//Register the listener for inbound messages.

mess conn . setmessagelistener(this);

//Start the message reading thread.

done = false

New thread (new reader ()). start();

} catch (IOException e) {

//Handling startup errors

}

}

//Asynchronous callback for inbound messages.

Public void notifyIncomingMessage {

if (conn == messconn) {

total++;

}

}

//Required MIDlet method-Release the connection and

//Notifies the reader that the thread is terminated.

public void pauseApp() {

done = true

Try {

mess conn . close();

} catch (IOException e) {

//Handling error

}

}

//the required MIDlet method-shutdown.

// @param unconditional forced shutdown flag

Public void destroyApp (Boolean unconditional) (

done = true

Try {

mess conn . setmessagelistener(null);

mess conn . close();

} catch (IOException e) {

//Handle the closing error.

}

}

//isolate the blocking I/O on a separate thread, so call back.

//You can return immediately.

Class readers implement Runnable {

The run method performs the actual message reading.

Public invalid operation () {

And (! Done) {

Try {

message mess = mess conn . receive();

} catch (IOException ioe) {

//Handling read errors

}

}

}

}

}