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: 2
Registered: ‎09-01-2008
My Device: Not Specified

invoke address book and grabbing a chosen contact

Friends:

 

I am trying to emulate functionality contained in the Wall Street Journal reader application ( so I know it's possible ).

 

In the WSJ app's menu, they have a "Tell a friend" item. When one presses on that item, a custom screen for composing an email appears, and on top of that they pop the BB's AddressBook app, which is surely done using the "Invoke API".

 

The functionality that I am looking for is what happens next: As soon as you click on a Contact name ( one that has an email defined ), the address book closes, and the email address appears in the custom compose email message screen. So they are some how listening in on the user's navigation through the address book, and immediately intervening ( closing the address book and grabbing the viewed contact data ) as soon as the user reaches something that the WSJ app can use.

 

At this URL: http://www.blackberryforums.com/developer-forum/110375-invoke-address-book-get-data.html ,

where another programmer had a question about a similar functionality, Mr. "set84" cryptically suggests this:

 

"using ApplicationMenuItem for add menu_item to Address Book and then via
eventOccurred in your application you can get access to user choise"

 

I've been playing around with extending ApplicationMenuItem, and I can see how if I post events from the "run()" member function, I can get the Contact information back in my app. But the WSJ app doesn't wait for a user to open the menu and press the new MenuItem. As soon as the contact name is chosen from the list ( a click on the trackball or the ENTER key ), the address book gets popped and the underlying WSJ app's screen is populated with the email address in the contact.

 

But ApplicationMenuItem might have some functionality that I don't know how to use, and isn't well documented.

 

The Javadocs show that ApplicationMenuItem has two different constructors. One of them is not shown in any of the examples I've seen:

 

ApplicationMenuItem.ApplicationMenuItem(Object context, int order)

 

The Javadocs also include this in the description:

 

"Developers should override this method to take custom actions on the context parameter."

 

Hmmm, but you cannot override a constructor.... can you?

 

And, even more interesting, from the JavaDoc of the ApplicationMenuItemRepository class, for each of the ID values with which a programmer registers his or her instance of a subclass of ApplicationMenuItem:

 

"The ApplicationMenuItem.ApplicationMenuItem(object,int) constructor receives a Contact instance as the context when an application menu item renders in this context."

 

That is for ApplicationMenuItems registered for "MENUITEM_ADDRESSCARD_VIEW".

 

But that's weird, since ApplicationMenuItemRepository.addMenuItem() is used to register an already constructed instance of an ApplicationMenuItem. How and where is this other constructor used?

 

My suspicion is that a separate instance of ApplicationMenuItem is created using this other constructor at the moment that a user chooses a contact ( since the menu for the screen gets populated when the new "address card view" screen is pushed by the AddressBook app, right? ). Since the "context" object passed to the is the selected Contact, it can then post the information back to the app, do a keystroke injection to pop off the address book and populate the email screen.

 

But how does the app get at that instance and play within this constructor, as the javadocs suggest??

 

That the WSJ app uses this to do what I described is only my suspicion from the clues I have found so far. I'd appreciate any help that readers of this forum could give me.

 

Thanks for your attention.

 

 

Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: invoke address book and grabbing a chosen contact

when you click on a contact in the simulator the debug window of the jde prints:
**ADN: Reading EF_ADN info
no clue what this means though, maybe there is a global event you can catch?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
New Developer
Posts: 2
Registered: ‎09-01-2008
My Device: Not Specified

Re: invoke address book and grabbing a chosen contact

yeah, i saw that too.

EF_ADN seems to have something to do with SIM cards. 

BlackBerry Development Advisor
Posts: 15,723
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: invoke address book and grabbing a chosen contact

Please have a look at the BlackBerryContactList.choose method.  It launches the Address Book, allows the user to select an entry and then returns that entry to your application.
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
Highlighted
New Developer
Posts: 20
Registered: ‎07-23-2008
My Device: Not Specified

Re: invoke address book and grabbing a chosen contact

Thanks Mark.

Developer
Posts: 74
Registered: ‎01-03-2010
My Device: Not Specified

Re: invoke address book and grabbing a chosen contact

use this

 

try {
    BlackBerryContactList contacts=(BlackBerryContactList)pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
		PIMItem selected=contacts.choose();
		if (selected!=null){
			if(selected instanceof Contact){
			    Contact selectedContact=(Contact)selected;
			    if(selectedContact.countValues(Contact.TEL)>0){
				int numValues = selectedContact.countValues(BlackBerryContact.TEL);
				String[] phoneNumbers = new String[numValues];
		                String[] labels = new String[numValues];  
			        for (int i = 0; i < numValues; i++) {
					String phoneNumber = selectedContact.getString(Contact.TEL, i);					                	
					String label = contacts.getAttributeLabel(selectedContact.getAttributes(Contact.TEL, i));
					         phoneNumbers[i] = phoneNumber;
					         labels[i] = label + ":" + phoneNumber;
	                        }  
		                if(numValues==0){
					m_input.setText("Sorry, no phone number available");
				}
			        else if(numValues==1){
					m_input.setText(phoneNumbers[0]);
			        }
		                else{
				      int choice = Dialog.ask("Which Number?", labels, 0);

				      if (choice > -1 && choice < numValues){
					    m_input.setText(phoneNumbers[choice]);
				      }
				      else{
					    m_input.setText("No number is selected!!!");
				      }
			        }
					                					           					            
                          }
		}				 
    }	

 

 

New Contributor
Posts: 6
Registered: ‎05-19-2010
My Device: bb curve 8520
My Carrier: developer

Re: invoke address book and grabbing a chosen contact

how i can get the txt in search field to use it in my custom search function.