BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 09-13-2007, 07:30 AM   #1 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Folder listener: It works with mails, but not with PINs

Please Login to Remove!

we have implemented a FolderListener/MessageListener.
It works very well with mails, does not work with PINs though.
As we inted to work with PINs this is quite unfortunate.
We are still waiting for a reply from RIM so i decided to give the forum a try

hope somebody comes up with an idea
attached is the complete class

Code:
public class InboxService implements FolderListener, MessageListener {

	private Store store;

	public InboxService() {
		try {
			Session session = Session.waitForDefaultSession();
			Logger.debug("InboxService.init() - session: " + session.getServiceConfiguration().getEmailAddress());
			store = session.getStore();
			store.addFolderListener(this);
			Logger.debug("InboxService.init() - Listener added to store");
		} catch (Exception e) {
			Logger.error("InboxService.init()", e);
		}
		
		Logger.debug("InboxService.init() - done");
	}

	public void destroyInboxService() {
		if (store != null) {
			store.removeFolderListener(this);
		}
	}

	private void processEvent(Message message) {
		if (message.isInbound() && message.getSubject().startsWith("DURCHBRUCH:")) {
			Logger.debug("InboxService.processEvent()");
			
			Object content = message.getContent();
			if (content instanceof BodyPart) {
				BodyPart bodyPart = (BodyPart) content;
				if (bodyPart.hasMore()) {						Logger.debug("InboxService.processEvent() - Message has more parts");
					
					if (!bodyPart.moreRequestSent()) {						message.addMessageListener(this);
						
						try {
							
							Transport.more(bodyPart, true);
						} catch (Exception e) {
							Logger.error("InboxService.processEvent()", e);
						}
					}
				} else {
					
					message.removeMessageListener(this);
					Logger.debug("InboxService.processEvent() - Removed MessageListener");
	
					
					try {
						if (message.getMessageType() == Message.PIN_MESSAGE) {
							Dialog.alert("Message received: " + message.getSubject());
						}
					} catch (Exception e) {
						Logger.error("InboxService.processEvent() - processing message failed", e);
					}
					
					try {
						
						Folder folder = message.getFolder();
						folder.deleteMessage(message);
						Logger.debug("InboxService.processEvent() - Deleted Message with subject: " + message.getSubject());
					} catch (Exception e) {
						Logger.error("InboxService.processEvent() - Deleting message failed", e);
					}
				}
			}
		}
	}

	
	public void changed(MessageEvent event) {
		processEvent(event.getMessage());
	}

	
	public void messagesAdded(FolderEvent event) {
		processEvent(event.getMessage());
	}

	
	public void messagesRemoved(FolderEvent event) {
		// nothing todo
	}
}
__________________
java developer, Devinto, hamburg/germany
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.