16
BlackBerry Device Applications Integration Guide
Open a message
1.
Retrieve the message store and the folder that contains the message.
Store store = Session.waitForDefaultSession.getStore();
Folder folder = Store.getFolder("SampleFolder");
2.
Retrieve the message objects from the folder. Iterate through the array and retrieve information, such as the
sender and subject, to display to the BlackBerry® device user.
Message[] msgs = folder.getMessages();
3. When a BlackBerry device user selects a message from the list, invoke methods on the
Message
object to
retrieve the appropriate fields and body contents to display to the BlackBerry device user.
Message msg = msgs[0]; // Retrieve the first message.
Address[] recipients = msg.getRecipients(Message.RecipientType.TO)
Date sent = msg.getSentDate();
Address from = msg.getFrom();
String subject = msg.getSubject();
Object o = msg.getContent();
// Verify that the message is not multipart.
if ( o instanceof String ) {
String body = (String)o;} //...
4. Invoke
getBodyText()
on a message to retrieve the plain text contents as a
String
. If the message does not
contain plain text, the method returns null.
Get more of a message.
By default, the first section of a message (typically about 2 KB) is sent to the BlackBerry® device.
1.
Create an instance of a subclass of the
BodyPart
abstract class.
TextBodyPart tb = new TextBodyPart(new MultiPart());
2. To determine if more data for a body part is available on the server, invoke
tb.hasMore()
.
3. To determine if the BlackBerry device user made a request for more data, invoke
tb.moreRequestSent()
.
4. To obtain a
Transport
object, invoke
Session.getTransport()
and store the returned
object in a variable of type
Transport
.
Transport trans = Session.getTransport();
5. To request more of a message
,
invoke
trans.more(BodyPart bp, boolean reqAll)
. The
second parameter of
more()
is a Boolean value that specifies whether to retrieve only the next
section of the body part (false) or all remaining sections of the body part (true).
if (( tb.hasMore() ) && (! tb.moreRequestSent()) {trans.more(tb,
true);}
Task
Steps
Summary of Contents for JAVA DEVELOPMENT ENVIRONMENT - - DEVICE APPLICATIONS INTEGRATION - DEVELOPMENT GUIDE
Page 4: ......
Page 7: ......
Page 10: ...10 BlackBerry Device Applications Integration Guide...
Page 12: ...12 BlackBerry Device Applications Integration Guide...
Page 50: ...50 BlackBerry Device Applications Integration Guide...
Page 56: ...56 BlackBerry Device Applications Integration Guide...
Page 65: ......
Page 66: ...2008 Research In Motion Limited Published in Canada...