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
Developer
Posts: 41
Registered: ‎03-07-2009
My Device: 9000 Bold
Accepted Solution

Regarding getting the selected word in email application

Hey, I have a question regarding how to get the selected word in the mail application. My application needs to get the selected word outside my application, and pass it back to the application. Thanks!

 

 

Developer
Posts: 19,624
Registered: ‎07-14-2008
My Device: Not Specified

Re: Regarding getting the selected word in email application

You are going to have to give us a bit more than this....

 

There are a number of options, including email listeners and application menu items, not to mention StringPatterns if the email is being displayed.  However to determine which option is the best we need to know how the word is selected.  Can you describe to use the processing that you wish to have happen?

 

I am presuming that you want to be displaying an email, select using the standard BB controls a piece of text, then get that back to your application.  In this case, an ApplicationMenuItem is probably what you want.  Alternatively, you might be able to do it by just telling your uses to 'Copy', which will put the text in the Clipboard, then process the Clipboard in your application. 

Developer
Posts: 41
Registered: ‎03-07-2009
My Device: 9000 Bold

Re: Regarding getting the selected word in email application

Hi Peter! Thanks for your reply :smileyhappy: I want to let user select some characters on the screen, say the user select "abc" by using the shift key and trackball. Now in the menu, I want to add an item named Define "abc". When user select it, it will run my applicaiton and pass abc to my applicaiton. Is there any way we can do it outside my own applicaiton? Thanks a lot!
Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Regarding getting the selected word in email application

See ApplicationMenuItem and ApplicationMenuItemRepository.

 

You create a menu item and add it to the email application. When the user selects your menu item, it calls your handler.

 

That should get you started.

 

Developer
Posts: 41
Registered: ‎03-07-2009
My Device: 9000 Bold

Re: Regarding getting the selected word in email application

Hi Rex, thanks for your reply. It works when we don't need know what the user select on the screen. We need to pass what user select on the screen to out applicaiton.  By ApplicationMenuItemRepository, we can open our applicaiton and pass whatever we want, but we can't access what the user select on the screen. Thanks:smileyhappy:

 

Steven

Developer
Posts: 19,624
Registered: ‎07-14-2008
My Device: Not Specified

Re: Regarding getting the selected word in email application

There is no published API that will give you this that I am aware of.  I think you have two options:

 

a) Tell the user to do a 'Copy' before invoking your ApplictionMenu.  You can check there is something in the clipboard and display to confirm that was what they intended.  This is what I would do, because it is safe and supported.

 

b) In your ApplicationMenu, you can possibly find and copy the selected are yourself as follows:

Field currentField = UiApplication.getUiApplication().getActiveScreen().getLeafWithFocus();

if ( currentField instanceof ActiveRichTextField ) {

artf = (ActiveRichTextField) currentField;

artf.selectionCopy(..);

}

 

Note that I have NOT tried or even compiled this code, and if might be that the Field is not an ActiveRichTextField, and you should also probably check that the Field is Selectable and/or the selection can be copied before doing this anyway.

Developer
Posts: 41
Registered: ‎03-07-2009
My Device: 9000 Bold

Re: Regarding getting the selected word in email application

Thanks for your reply. The latter method works. Thanks again.

 

Steven 

Developer
Posts: 19,624
Registered: ‎07-14-2008
My Device: Not Specified

Re: Regarding getting the selected word in email application

Good news.

 

Can I suggest that you mark this Thread as solved, so that other don't review it thinking you still need help.  For futher info on this, see: 

http://supportforums.blackberry.com/rim/help_faq#solution_whatis