Add a listener to a folder

  1. Import the required classes and interfaces.
    import net.rim.blackberry.api.mail.event.FolderListener;
    import net.rim.blackberry.api.mail.Folder;
    import net.rim.blackberry.api.mail.Store;
    
  2. Implement FolderListener.messagesAdded() and FolderListener.messagesRemoved().
    void messagesAdded(FolderEvent e) 
    {
       // Perform processing on added messages.
    }
    void messagesRemoved(FolderEvent e) 
    {
       // Perform processing on removed messages.
    }
  3. Retrieve the Folder object for which you want to receive new message notifications.
    Folder[] folders = store.list(Folder.INBOX);
    Folder inbox = folders[0];
  4. Register the class that implements FolderListener with the folder.
    inbox.addFolderListener(this);

Was this information helpful? Send us your comments.