To encode an MMS message, first you need to create an MmsMessage object. Fill its fields an then simply instance MmsEncoder.
Example:
import java.io.UnsupportedEncodingException;
import java.util.Random;
import net.sourceforge.jmmslib.*;
class EncodingExample{
public static void main(String args[]){
//Create the message bean
MmsMessage mms = new MmsMessage();
Random r = new Random();
try{
//Set the sender and receiver addresses (xxxxxxxxxxx should be a valid phone number)
mms.setMessageSender("xxxxxxxxxxxxx", MmsMessage.MMS_ADDRESS_TYPE_MOBILE_NUMBER);
mms.addMessageReceiver("xxxxxxxxxxxxx", MmsMessage.MMS_ADDRESS_TYPE_MOBILE_NUMBER);
//Set the transaction id
mms.setTransactionID(String.valueOf(r.nextInt(999999999)));
//Set the date of the MMS
mms.setMessageDate(System.currentTimeMillis());
//Set the subject
mms.setMessageSubject("This is a cool subject!");
//Set the content type... usually MULTIPART
mms.setMessageContentType(MmsMessage.CTYPE_APPLICATION_MULTIPART_MIXED);
//Set the content type...
mms.setMessageType(MmsMessage.MMS_MESSAGE_TYPE_SEND_REQUEST);
//Set the MMS version used
mms.setVersion(MmsMessage.MMS_VERSION_1);
//Create a part object and fill it
MmsPart p = new MmsPart();
p.setPartContent(new String("This is a text part").getBytes("US-ASCII"));
p.setPartContentType(MmsMessage.CTYPE_TEXT_PLAIN);
//Add the part to the message
mms.addPart(p);
}catch(MmsMessageException e){
e.printStackTrace();
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
//Create the encoder for the specified MMS.
MmsEncoder encoder = new MmsEncoder(mms);
try {
//Encode the message
byte encodedMMS[] = encoder.encodeMessage();
} catch (MmsEncodingException e) {
e.printStackTrace();
}
}
}