Help Center

Local Navigation

Create a custom folder in the message list

To be able to perform operations on custom messages, the BlackBerry® device application must register at least one custom folder.

  1. Import the following classes:
    • net.rim.blackberry.api.messagelist.ApplicationMessageFolderRegistry
    • net.rim.blackberry.api.messagelist.ApplicationMessageFolder
  2. Import the following interfaces:
    • net.rim.blackberry.api.messagelist.ApplicationMessage
    • net.rim.device.api.collection.ReadableList
    • net.rim.blackberry.api.messagelist.ApplicationMessageFolderListener
  3. Create a class that implements the ApplicationMessage interface.
    public class MLSampleMessage implements ApplicationMessage
  4. Obtain a reference to the ApplicationMessageFolderRegistry.
    ApplicationMessageFolderRegistry reg = ApplicationMessageFolderRegistry.getInstance();
  5. Register an BlackBerrydevice application folder for each collection of messages.
    ReadableList inboxMessages = messages.getInboxMessages(); // collection with MLSampleMessage elements
    ReadableList deletedMessages = messages.getDeletedMessages(); // collection with MLSampleMessage elements
    ApplicationMessageFolder inboxFolder = reg.registerFolder( INBOX_FOLDER_ID, "Inbox", inboxMessages );
    ApplicationMessageFolder deletedFolder = reg.registerFolder( DELETED_FOLDER_ID, "Deleted Messages",   
    deletedMessages, false );
  6. Let an BlackBerrydevice application be notified when specific folder events occur.
    deletedFolder.addListener( this , ApplicationMessageFolderListener.MESSAGE_DELETED );
  7. Create a class that implements the ApplicationMessageFolderListener interface.
    public class AppFolderListener implements ApplicationMessageFolderListener
  8. To let an BlackBerrydevice application perform actions when a folder event occurs, implement the actionPerformed() method of the ApplicationMessageFolderListener interface.
    public void actionPerformed( int action, ApplicationMessage[] messages, ApplicationMessageFolder folder ) {
      // check if action was performed on multiple messages
    if( messages.length == 1 ) {
      switch( action ) {
      case ApplicationMessageFolderListener.MESSAGE_DELETED:
      messageStore.deleteInboxMessage( message );
  9. Set the root folder for the folders of the BlackBerry device application. The name of the root folder appears in the View Folder dialog of the Message list application when a BlackBerry device application registers more than one application message folder.
    reg.setRootFolderName( "ML Sample" );

Index


Was this information helpful? Send us your comments.