Java Reference
In-Depth Information
the
MessageConnection
instance configured for MT messages—but message handling is
trickier, because the message may contain any number of message parts. The receive
thread checks to be sure that the
Message
it received from the
MessageConnection
instance is a
MultipartMessage
instance, and then examines each of its parts to find a
part with the MIME type
image/png
. Once it does so, it creates an instance of
Image
using the bytes from that part. It then updates the display with the image from that
part with the inner class
SetImage
. Finally, the thread's
run
loop resumes waiting on the
monitor variable for another incoming message notification.
Like the SMSMIDlet example, sending also occurs on a separate thread; the
MMSSender
class manages the sending of each outgoing message. Listing 14-9 shows the
MMSSender
class.
Listing 14-9.
The MMSSender Class
package com.apress.rischpater.mmsmidlet;
import javax.microedition.io.*;
import javax.wireless.messaging.*;
import java.io.*;
public class MMSSender implements Runnable {
private static MMSSender me = new MMSSender();
private MMSSender() {
}
public static MMSSender getInstance() {
return me;
}
private String receiver = null;
private String appId = null;
private String image = null;
private String msg = null;
private String encoding = null;
private boolean sending = false;
public void sendMsg(String r, String id, String m, String i) {
if (sending) return;
receiver = r;
appId = id;
msg=m;
image = i;
encoding = System.getProperty("microedition.encoding");