BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 05-08-2007, 07:34 AM   #1
L Jorissen
Knows Where the Search Button Is
 
Join Date: May 2007
Model: 8707
PIN: N/A
Carrier: Proximus
Posts: 16
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, 03:05 AM   #2
L Jorissen
Knows Where the Search Button Is
 
Join Date: May 2007
Model: 8707
PIN: N/A
Carrier: Proximus
Posts: 16
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



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


Altair WBS-202 Dual channel wireless intercom base station picture

Altair WBS-202 Dual channel wireless intercom base station

$1350.00



MSA Altair 4X multigas detector Monitor Meter Glow In The Dark/Calibrated picture

MSA Altair 4X multigas detector Monitor Meter Glow In The Dark/Calibrated

$450.00



MSA Altair 5X Gas Detector Industrial Kit  10116926 - LEL, O2, CO, H2S picture

MSA Altair 5X Gas Detector Industrial Kit 10116926 - LEL, O2, CO, H2S

$1899.00



MSA Altair 4X Gas Detector 4 Gas LEL O2 CO H2S Warranty Certified Calibration picture

MSA Altair 4X Gas Detector 4 Gas LEL O2 CO H2S Warranty Certified Calibration

$250.00



Altair2X Co Instrument CO Gas Detector picture

Altair2X Co Instrument CO Gas Detector

$399.99



MSA Altair 5X Replacement MSA Sensor MSA  NH3 Ammonia Surplus #10106726 picture

MSA Altair 5X Replacement MSA Sensor MSA NH3 Ammonia Surplus #10106726

$299.99







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