Help Center
Local Navigation
- Integrating with BlackBerry Device Software applications
- Message list
- Create a new blank SMS text message
- Create a new populated text message
- Create a new blank MMS message
- Create a new blank email message
- Create a new populated email message
- Create a new blank PIN message
- Create a new populated PIN message
- Receive a message notification
- Add a listener to the message store
- Add a listener to the message store for batch updates
- Add a listener to a folder
- Retrieve the total count of unread email messages in all folders in the store
- Open a message
- Retrieving the body of an email message
- Notify a BlackBerry device application that an email message is about to be sent
- Notify a BlackBerry device application that an MMS message is about to be sent
- Notify a BlackBerry device application that an SMS message is about to be sent
- Send a message
- Reply to a message
- Forward a message
- Work with message folders
- Attachments
- Calendar
- Contact list
- Task list
- Phone
- BlackBerry Browser
- Menu items
- Glossary
- Provide feedback
- Document revision history
- Legal notice
BlackBerry Manuals & Help
>
Developer Documentation
>
Java Development Guides and API Reference
>
Development Guide
Integration - BlackBerry Java Application - 5.0
Open a message
- Import the required classes and interfaces.
import java.util.Date; import net.rim.blackberry.api.mail.Address; import net.rim.blackberry.api.mail.Folder; import net.rim.blackberry.api.mail.Message; import net.rim.blackberry.api.mail.Session; import net.rim.blackberry.api.mail.Store;
- Invoke Session.waitForDefaultSession.getStore() to retrieve the message store.
Store store = Session.waitForDefaultSession.getStore();
- Invoke Store.getFolder() to retrieve the folder that contains the message.
Folder folder = Store.getFolder("SampleFolder"); - Invoke folder.getMessages() to retrieve the message objects and store the message objects in a Message array. Iterate through the array and retrieve information, such as the sender and subject, to display to the BlackBerry® device user.
Message[] msgs = folder.getMessages();
- When a 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 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; } //... - Invoke Message.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.
Next topic: Retrieving the body of an email message