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.

inside custom component

Java Development

Reply
New Developer
Posts: 7
Registered: ‎01-14-2009
My Device: Not Specified

Context Sensitive AddMenuItem

I have added a menu item to the MENUITEM_EMAIL_VIEW for users to be able to click when they are viewing a message. Is it possible to have this menu item only appear based on the what the subject header, or sender is? I only want this to appear for certain messages.

 

Thanks!

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Context Sensitive AddMenuItem

No, this is not possible.

 

New Developer
Posts: 7
Registered: ‎01-14-2009
My Device: Not Specified

Re: Context Sensitive AddMenuItem

That's unfortunate. Then how do the default menu's differ between an e-mail / meeting invite? The meeting invites show up with the options 'Accept' and 'Decline' and regular e-mails do not have that option. There should be a way to do this.

 

I saw something about listening to folder events, not sure if that is the a step in the right direction or not?

Any help is appreciated.

 

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Context Sensitive AddMenuItem

FolderListener only allows you to detect a new Email arriving in the folder.

 

The menu items you mention are probably placed by custom attachment handlers, not by ApplicationMenuItem. You can implement one of these yourself.

 

See the API docs for AttachmentHandler.

 

New Developer
Posts: 7
Registered: ‎01-14-2009
My Device: Not Specified

Re: Context Sensitive AddMenuItem

[ Edited ]

I'm not dealing with attachments for this application, just regular e-mails.

 

Here is a snippet of my code to add a button:

 

Menu()
{
ApplicationMenuItemRepository amir = ApplicationMenuItemRepository.getInstance();
amir.addMenuItem(ApplicationMenuItemRepository.MENUITEM_EMAIL_VIEW, new MyMenuItem();
}

private static class MyMenuItem extends ApplicationMenuItem {
private String menutext;

MyMenuItem()
{
super(20);
menutext = "My Button";
}

 

 I.E I want to make it so the button doesn't show up with e-mails with the subject header: 'Something'

 

Message Edited by Kalamity on 01-14-2009 01:12 PM
Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Context Sensitive AddMenuItem

Nope. There are your options (AFAIK)

 

1. You can listen for incoming emails, inspect the subject line, and do something there.

 

2. You can place your ApplicationMenuItem (as you have done), then inspect the incoming "Object context" (the message object, in this case), and do something there. You could ignore non-conforming messages, or put up an error dialog, whatever.

 

3. You can attach something to the email, and write your own attachment handler, adding your menu item from the attachment handler.

 

Of course, this is just my opinion, I could be wrong. YMMV. :smileyhappy:

 

New Developer
Posts: 7
Registered: ‎01-14-2009
My Device: Not Specified

Re: Context Sensitive AddMenuItem

Thanks, I was afraid I was going to get that answer. I have already implemented error checking for option 2, and it will give display a msgbox saying 'Invalid Msg Type' if I don't want to handle that type of message and exit. I guess the only benefit of being able to 'hide' these buttons on invalid e-mails would be saving on screen real estate (and maybe please some less intelligent users).

 

Option 1 would be nice, but I need it to work for e-mails that already exist, not just what is currently incoming. I guess I could mix this in with what was already implemented, but it might turn into more of an annoyance to the user if something showed up everytime a certain message entered their mailbox.

 

I don't have any control on what e-mails are being sent, so the the 3rd option with the attachment handler idea won't work for me.

 

Maybe sometime in the future RIM will add some other handle into their API to allow this, like net.rim.blackberry.api.mail.checker.subject / sender; do to some checking on messages when the blackberry button is pressed on the mail screen.

 

Thanks for your help RexDoug! :smileywink:

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Context Sensitive AddMenuItem

Actually, you *can* get an array of the existing Message objects in a folder - see Folder.getMessages().

 

Maybe a combination of the two, extract this list at startup, do your dirty deed, then attach a listener to the folder for new email.

 

Here is another thing to consider: you can create a MessageListener, and attach it to all of the messages. Your handler will then get a MessageEvent every time a message is opened.

 

I don't know exactly what it is you are trying to do to these messages, but this might just suffice.

 

New Developer
Posts: 88
Registered: ‎11-04-2008
My Device: Not Specified

Re: Context Sensitive AddMenuItem

i have the same issue with Kalamity. What i'm trying to do right now is add a menu item to email views, but i want it only to appear on RECEIVED email items, not including the SENT emails. The ApplicationMenuItemRepository.MENUITEM_EMAIL_VIEW adds the menu item on both received and sent emails. I tried the other options that you recommended, it works, but it would be so inconvinient to the user, also hiding processes from the user would take up so much space and would probably slow down the performance of the BlackBerry. This is just my opinion, though. Still trying to find a way to solve this issue. :smileyhappy:

 

Anyone from RIM out there? can you possibly help us with this?

BlackBerry Development Advisor
Posts: 14,952
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: Context Sensitive AddMenuItem

The ApplicationMenuItem API does not support not showing a menu item for sent items.  It would appear for all messages, as you have described.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker