Java Reference
In-Depth Information
public void notifyIncomingMessage(MessageConnection msgConn) {
if (msgConn == conn)
getMessage();
}
class SetImage implements Runnable {
private Image img = null;
public SetImage(Image inImg) {
img = inImg;
}
public void run() {
mColorSquare.setImage(img);
}
}
}
The MessageConnection is opened in server mode. Unlike SMS, MMS uses an application
ID instead of a port to identify the message routing endpoint. Our application ID is stored
as mAppID and is set to “MMSMIDlet”. Once the MessageConnection is obtained from
Connector.open() , MMSMIDlet is registered as the MessageListener for incoming messages.
The startReceive() method starts a receive thread that will pick up and process the
incoming MMS messages. Initially, this thread will be blocked, waiting on a monitor called
mMonitor . This thread will be notified whenever an incoming MMS message arrives, in the
getMessage() method. In the run() method, you can see that receive() is used to pick up the
pending MMS message. The MessagePart that has the image is then extracted, and the image is
displayed on the GUI.
Sending MMS Messages with MMSSender
The MMSSender class is used by MMSMIDlet to send multipart messages. Each outgoing message
is sent on a new thread. The source code of the MMSSender class is shown in Listing 11-4.
Listing 11-4. Sending MMS Messages with MMSSender
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.wireless.messaging.*;
import java.io.*;
public class MMSSender implements Runnable {
private static MMSSender inst = new MMSSender();
private MMSSender() {
}
public static MMSSender getInstance() {
return inst;
}
private String mReceiver = null;
private String mAppID = null;
Search WWH ::




Custom Search