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