BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 05-08-2007, 08:34 AM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: May 2007
Model: 8707
PIN: N/A
Carrier: Proximus
Posts: 16
Post Thanks: 0
Thanked 0 Times in 0 Posts
Question Object context in email view screen

Please Login to Remove!

Hello,

I have a strange problem. I've added a menuitem to the MENUITEM_EMAIL_VIEW so I'd expect the object to be passed into the run method to be of type "Message". This appears not to be the case because when run, I end up in the "else" part of my code, so the context object is not of type Message.

1) What is wrong in my code?
2) Eventually, I want to retrieve the sender, date, subject,... of the message for further use. How can I do this?

Code:
package com.rim.samples.docs.menuitem;

import net.rim.device.api.system.*;
import net.rim.device.api.ui.component.Dialog.*;
import net.rim.blackberry.api.menuitem.*;
import net.rim.blackberry.api.mail.*;
import java.util.*;

public final class DemoAppMenuItem extends Application {
    public static void main(String[] args) {
        DemoAppMenuItem app = new DemoAppMenuItem();
        app.enterEventDispatcher();
    }

    DemoAppMenuItem() {
        ApplicationMenuItemRepository amir = ApplicationMenuItemRepository.getInstance();
        amir.addMenuItem(ApplicationMenuItemRepository.MENUITEM_EMAIL_VIEW, new SampleMenuItem());
    }

    public class SampleMenuItem extends ApplicationMenuItem
    {
        SampleMenuItem() {
            super(20);
        }
        
        public String toString() {
            return "Give me more!";
        }
        
        public Object run(Object context) {            
            if (context instanceof Message){
                Message msg = (Message)context;
                net.rim.device.api.ui.component.Dialog.alert("We're in!!");
            }
            else {
                net.rim.device.api.ui.component.Dialog.alert("Context was not a message!");
            }
            return null; 
        }
    }
}


Best regards, L J
Offline  
Old 05-10-2007, 04:05 AM   #2 (permalink)
Knows Where the Search Button Is
 
Join Date: May 2007
Model: 8707
PIN: N/A
Carrier: Proximus
Posts: 16
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default [SOLVED] Object context in email view screen

Hello again,

I found the solution!! Joehoe! It appears that the 3 messages that are standard in the "Messages" application in the device simulator are NO REAL email messages That's the reason why the context object is something, but no message object. I've composed an email on the simulator and for that one, my code worked.
I also figured out how to retrieve the contents of the email message. Like this: (code comes in run method)
Code:
if(context instanceof Message){
                Message msg = (Message)context;
                Dialog.alert("We're in!!");
                try {
                    Address[] recipients = msg.getRecipients(Message.RecipientType.TO);
                    Dialog.alert("The recipients: " + recipients);
                    Date sent = msg.getSentDate();
                    Dialog.alert("Sent on: " + sent);
                    Address from = msg.getFrom();
                    Dialog.alert("Sender: " + from);
                    String subject = msg.getSubject();
                    Dialog.alert("Subject: " + subject);
                    String bodytxt = msg.getBodyText();
                    Dialog.alert("Message: " + bodytxt);
                }
                catch(MessagingException e)
                {
                    Dialog.alert(e.getMessage());
                }


Hope you can learn from this.
Best regards, L J.
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.