BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 07-18-2008, 11:06 AM   #1 (permalink)
New Member
 
Join Date: Jul 2008
Model: 7290
PIN: N/A
Carrier: Rogers
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default FolderListener Application

Please Login to Remove!

Hello,

I was testing out a sample application from RIM and it's not working like I expected it to.

na.blackberry.com/eng/developers/resources/labs/listeningforemail.jsp

To my understanding, this app would alert me if an email from the INBOX with subject "<TAG>" was received, and would play a notification. Problem is it plays the notification for ANY new incoming email, "<TAG>" or not.

Can someone tell me what's wrong?


Basically I'm trying to create and app that would read the inbox for a particular type of email and have a popup dialog box upon receiving that particular type of email. If anyone knows where I can look to implement a popup dialog box that would be great as well.

Thanks!
Offline  
Old 07-18-2008, 09:22 PM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default

I've never used the lab code, but the listener does work, I've used it for the purpose you propose (as have others). Have you tried stepping through the listener method with the debugger?
Offline  
Old 07-19-2008, 09:26 AM   #3 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

That sample code is broken in several respects. Don't use it as a model - especially the "newConfiguration" object (it will trash your profiles if installed on the device).

However, the basic idea is there. It is up to you to decide what criteria to use for filtering the emails.
Offline  
Old 07-21-2008, 09:14 AM   #4 (permalink)
New Member
 
Join Date: Jul 2008
Model: 7290
PIN: N/A
Carrier: Rogers
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey guys thanks for the responses

I never tried the debugger because I can't get email setup to work properly on the simulator. I tried to setup my ESS to point to my gmail smtp and pop server but it just wouldn't happen. So I uploaded the code onto the BB to see how it works but for some reason it just alerts any emails not just the ones with the subject line. I'm stumped...



Doug - I don't understand what "newConfiguration" is doing, I just left it as is to test out the sample. I'm pretty new to BB development (1st week) so any help is appreciated. Thanks!


Code:
/**
         * It is likely that the following call will return a separate config object for each SourceID, such as data
         * that describes user set notification settings. However, for this example, we a trivial, arbitrary conifg object
         */
        public Object newConfiguration(long consequenceID, long sourceID, byte profileIndex, int level, Object context) {
            byte[] myConfig = new byte[] {'m', 'y', '-', 'c', 'o', 'n', 'f', 'i', 'g', '-', 'o', 'b', 'j', 'e', 'c', 't'};
            return myConfig;
        }
Offline  
Old 07-24-2008, 09:52 AM   #5 (permalink)
New Member
 
Join Date: Jul 2008
Model: 7290
PIN: N/A
Carrier: Rogers
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

So I have a class that can open a dialog box when called. But I'm having trouble getting my FolderListenerApp to make the call to run that dialog program.

This is from my folderlistener class, where after the notification is triggered I try to make a call to my DialogExample class to display a dialog...
Code:
//method that is executed when a message is added
    public void messagesAdded(FolderEvent e) {
        //get the message and folder it was added to
        Message orginalMessage = e.getMessage();
        Folder messageFolder = orginalMessage.getFolder();

        //check that the folder was the inbox
        if (messageFolder.getType() == Folder.INBOX) {
            System.out.println("Message has arrived");

            //get the message subject
            String subject = orginalMessage.getSubject();
            //check the message for the tag
            if (subject.indexOf("<TAG>") != -1) {
                System.out.println("Message has tag, activate notification");
                
                NotificationsManager.triggerImmediateEvent(MessageNotification.NOTIFICATION_ID, 0, this, null);                
                                
                DialogExample de = new DialogExample();
                de.enterEventDispatcher();
            }
        }
    }

This is my DialogExample class which does the dialog UI. I'm trying to have the listener call this dialog when mail comes in.
Code:
package com.rim.samples.folderlistenerapp;

import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;

public class DialogExample extends UiApplication {
    public static void main(String[] args) {
        DialogExample instance = new DialogExample();
        instance.enterEventDispatcher();
    }
    
    public DialogExample() {
        pushScreen(new DialogScreen());
    }
    
    class DialogScreen extends MainScreen {
    
        LabelField instructionLabel = new LabelField("YOU HAVE IMPORTANT MAIL!!!");
        
        public DialogScreen() {
            setTitle("COMPANY");
            add(instructionLabel);
        }
        
        public boolean onClose() {
            int response = Dialog.ask(Dialog.D_YES_NO, "Are you sure you want to quit?");
            if (Dialog.YES == response) {
            System.exit(0);
            } else {
            return true;
            }
            return super.onClose();
        }
    }
}
Any help is appreciated, thanks.
Offline  
Old 07-24-2008, 10:37 AM   #6 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

You cannot open a dialog in FolderListener - your code is being executed by the calling message thread, not your event thread. Only *your* event thread can create a dialog in your application.
Offline  
Old 07-24-2008, 03:29 PM   #7 (permalink)
New Member
 
Join Date: Jul 2008
Model: 7290
PIN: N/A
Carrier: Rogers
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

So what can I do to have my FolderListener pop up an alert telling me there's an email, instead of playing that annoying tune?
Offline  
Old 07-24-2008, 03:57 PM   #8 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

Tough question to answer without understanding the architecture of your application. One class to look at might be UiApplication.invokeLater().

You create a Runnable object that invokes your dialog, the pass this to invokeLater(). Your runnable object is then invoked by your event thread as soon as possible.

So, for example, you might create a class called "AlertDisplayer" that implements the Runnable interface. In the run() method, you pop up your Alert Dialog.

Then, you invoke UiApplication.invokeLater(), passing the instantiated AlertDisplayer.
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.