Java Reference
In-Depth Information
Step 1 is identical to the SMS case. The next section shows you how to perform steps 2 and
3. Once you've created and populated a MessagePart and set the relevant headers, you can add
it to a MultipartMessage using this method:
public void addMessagePart(MessagePart part);
Accessing Content of Message Parts
A message part consists of content (the payload) and header. The header contains MIME type
information, the encoding used, the content ID, and the content location. The MessagePart
class allows you to work with individual message parts. To create a new MessagePart , you can
use one of its constructors:
public MessagePart(byte[] contents, int offset, int length, String mimeType,
String contentId, String contentLocation, String encoding);
public MessagePart(byte[] contents, String mimeType, String contentId,
String contentLocation, String encoding)
public MessagePart(InputStream is, String mimeType, String contentId,
String contentLocation, String encoding);
The first two methods set the contents of the message part from a byte array, while the last
one does so from an InputStream (for larger content such as audio or video). The first variant of
the byte array methods allows you to specify an offset and length to extract part of the byte
array as content. The second form uses the entire input byte array.
To access the content of a MessagePart , you can use the following:
public byte[] getContent();
public InputStream getContentAsStream();
For processing small-sized content, working with a byte array may be convenient. For very
large multimedia content, especially audio and video, using getContentAsStream() can provide
more usable access to the content.
MessagePart Header Information
You can use other methods of MessagePart to access header information:
public String getContentEncoding();
public String getMIMEType();
public String getContentID();
public String getContentLocation();
public int getLength();
The last method, getLength() , returns the length of the content in bytes.
A MIDlet to Send and Receive MMS
Putting the WMA 2.0 MMS API to work, the example presented in this section is a modification
of the SMSMIDlet . The user interface is identical.
Search WWH ::




Custom Search