Java Reference
In-Depth Information
Listing 16-18. Revisions to the MMSSender Class to Enable You to Send a Captured Image
via MMS
public class MMSSender implements Runnable {
private byte[] imageBytes;
public void sendMsg(String r, String id, String m, byte[] bi) {
if (sending) return;
receiver = r;
appId = id;
msg=m;
imageBytes = bi;
encoding = System.getProperty("microedition.encoding");
Thread t = new Thread(this);
t.start();
}
public void sendMMS() {
String address = "mms://" + receiver + ":" + appId;
System.out.println(address);
MessageConnection c = null;
try {
c = (MessageConnection) Connector.open(address);
MultipartMessage mpm = (MultipartMessage) c.newMessage(
MessageConnection.MULTIPART_MESSAGE);
mpm.setSubject("An Image");
if (image != null) {
InputStream is = getClass().getResourceAsStream(image);
imageBytes = new byte[is.available()];
is.read(imageBytes);
}
if (imageBytes != null) {
mpm.addMessagePart(
new MessagePart(
imageBytes, 0, imageBytes.length,
"image/png", "id1", null, null));
}
if (msg != null) {
byte[] bMsg = msg.getBytes();
mpm.addMessagePart(
new MessagePart(bMsg, 0, bMsg.length,
"text/plain", "txt1", null, encoding));
}
c.send(mpm);
 
Search WWH ::




Custom Search