12-16-2009 11:27 AM
I am having trouble creating an application menu item. I have looked at plenty of examples and cannot get it to work. If I have the application add a menu item to the email menu and the application is set to run on start up, that should make the menu item show up correct? Here is the code I am using.
This is in my application class.
(new MyMenuItem(0)).registerInstance();
This is the class adding the menu item in the BB email application.
import net.rim.blackberry.api.mail.Message; import net.rim.blackberry.api.menuitem.ApplicationMenuItem; import net.rim.blackberry.api.menuitem.ApplicationMenuIte mRepository; class MyMenuItem extends ApplicationMenuItem { // using the default constructors here. public MyMenuItem(int order) { super(order); } // Register the instance of the menuItem with the system public void registerInstance() { // System.out.println("Registering MyMenuItemDemo"); ApplicationMenuItemRepository.getInstance().addMen uItem(ApplicationMenuItemRepository.MENUITEM_EMAIL _VIEW, this); } // methods we must implement // Run is called when the menuItem is invoked public Object run(Object context) { // context object should be a email message if (context instanceof Message) { Message message = (Message) context; // this is where we would work the message // do something here } return context; } // toString should return the string we want to // use as the lable of the menuItem public String toString() { return "My Menu Item!"; } }
Thanks for the help in advance.
12-16-2009 12:16 PM - edited 12-16-2009 12:17 PM
Code looks OK, have you debugged to confirm that it is being executed?
If you plan to remove this item at any stage (say because of a user option), you will have to keep a reference to it.
12-16-2009 12:24 PM
Hi,
Well there is no issue in your Code, Its look fine.. I recently done same think and its working fine...
One suggestion is - Have try this code with any other order instead of 0(zero).
Like :
(new MyMenuItem(20)).registerInstance();
12-16-2009 12:34 PM
I debugged it and it is running the code. Turns out its not doing what I expected. I added menu items to address book and calendar and those appeared. They just didn't work for the email view. So my code works I just need to figure out why its not working for email view. Thanks for you help.
12-16-2009 12:49 PM
Have you tried same code with different OS versions?
12-16-2009 03:05 PM
I have not. But I can see my custom menu item in the email view now.
My next problem is that it does not show the menu item on the actual phone even though I have the project set to run on startup in the blackberry properties. Once the program is run manually the menu item shows up. It works on startup in the eclipse simulator.
12-16-2009 05:39 PM
If Application Permissions is not alllowing email access, then this attempt to add the menu item will fail wiht a ControlledAccessException
12-17-2009 10:06 AM
How do I set those permissions?
12-17-2009 10:11 AM
Take a look at ApplicationPermissions sample which comes from BB JDE 4.2.1
07-21-2010 10:40 AM
I would play with the context ID. I believe ApplicationMenuItemRepository.MENUITEM_EMA
Try MENUITEM_MESSAGE_LIST or MENUITEM_EMAIL_EDIT instead...