Welcome!

Welcome to the Official BlackBerry Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
New Developer
Paulg568
Posts: 9
Registered: ‎12-15-2009

Can't add ApplicationMenuItem

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.ApplicationMenuItemRepository;

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().addMenuItem(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.

 

Please use plain text.
Developer
peter_strange
Posts: 17,653
Registered: ‎07-14-2008

Re: Can't add ApplicationMenuItem

[ Edited ]

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. 

Please use plain text.
Developer
Nidhi
Posts: 31
Registered: ‎10-09-2009

Re: Can't add ApplicationMenuItem

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();
Please use plain text.
New Developer
Paulg568
Posts: 9
Registered: ‎12-15-2009

Re: Can't add ApplicationMenuItem

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.

Please use plain text.
New Developer
yvedpathak
Posts: 9
Registered: ‎12-15-2009
My Carrier: Vodafone

Re: Can't add ApplicationMenuItem

Have you tried same code with different OS versions?

Please use plain text.
New Developer
Paulg568
Posts: 9
Registered: ‎12-15-2009

Re: Can't add ApplicationMenuItem

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.

Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008

Re: Can't add ApplicationMenuItem

If Application Permissions is not alllowing email access, then this attempt to add the menu item will fail wiht a ControlledAccessException

 

 

 

Please use plain text.
New Developer
Paulg568
Posts: 9
Registered: ‎12-15-2009

Re: Can't add ApplicationMenuItem

How do I set those permissions?

Please use plain text.
Developer
yosoh
Posts: 213
Registered: ‎07-18-2008

Re: Can't add ApplicationMenuItem

Take a look at ApplicationPermissions sample which comes from  BB JDE 4.2.1

--------------------------------------------------
problemSolved() ? kudosPlease():kudosPlease();
Please use plain text.
New Developer
sugarat
Posts: 14
Registered: ‎01-01-2009

Re: Can't add ApplicationMenuItem

I would play with the context ID.  I believe ApplicationMenuItemRepository.MENUITEM_EMAIL_VIEW will have the menu item show in an email message in view mode, e.g. opening an existing message.  I'm assuming you don't have many messages sitting in your simulator's inbox.

 

Try MENUITEM_MESSAGE_LIST or MENUITEM_EMAIL_EDIT instead...

Please use plain text.