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
Contributor
yoshiegg
Posts: 22
Registered: ‎06-02-2010
My Device: 8330
My Carrier: Rogers & Bell

How to pull the phone number from addrebooklist / addressbook view context?

Hello all, I am made a menu item for the addressbook and I am trying to figure out how to target a specific phone number (the one that the user is selecting) similer to the device dialer behavior.

 

The menu item works and fires my code and I figured out how to pull the phone number from the phone dialer and the recent calls list. However the addressbook is more complex because it has multiple numbers and I have no idea how to extract the selected number in this case. Please see my code below that currently works for the dialer and recent call list.

 

 

 

import net.rim.blackberry.api.menuitem.ApplicationMenuItem;
import net.rim.blackberry.api.menuitem.ApplicationMenuItemRepository;

public class MainMenuHandler extends ApplicationMenuItem {
MyListener m_oListener;

public MainMenuHandler(int order, MyListener pListener){
super(order);
m_oListener = pListener;
}

public Object run(Object context) {

// check what context fired this event.
if (context instanceof net.rim.blackberry.api.phone.phonelogs.PhoneCallLog) {
net.rim.blackberry.api.phone.phonelogs.PhoneCallLog call = (net.rim.blackberry.api.phone.phonelogs.PhoneCallLog)context;
String num = call.getParticipant().getAddressBookFormattedNumber();
if(num.length() >= 3 && num.length() <= 12) {
m_oListener.ProcessPhone(num);
}
}

// When the phone dialer menu triggers we only get a string with the number. How easy is that!
if (context instanceof String) {
String num = context.toString();
if(num.length() >= 3 && num.length() <= 12) {
m_oListener.ProcessPhone(num);
}
}


// !!!!!!!!!!!!!! THIS IS WHERE I WANT TO READ THE SELECTED ADDRESSBOOK NUMBER !!!!!!!!!!!!!

return null;
}

public String toString() {
return "Test phone number.";
}

// Register the instance of the menuItem with the system
public void registerInstance() {
ApplicationMenuItemRepository.getInstance().addMenuItem(ApplicationMenuItemRepository.MENUITEM_PHONELOG_VIEW,this);
ApplicationMenuItemRepository.getInstance().addMenuItem(ApplicationMenuItemRepository.MENUITEM_PHONE,this);
ApplicationMenuItemRepository.getInstance().addMenuItem(ApplicationMenuItemRepository.MENUITEM_ADDRESSCARD_VIEW,this);
}

// UN-Register the instance of the menuItem with the system
public void unRegisterInstance() {
ApplicationMenuItemRepository.getInstance().removeMenuItem(ApplicationMenuItemRepository.MENUITEM_PHONELOG_VIEW,this);
ApplicationMenuItemRepository.getInstance().removeMenuItem(ApplicationMenuItemRepository.MENUITEM_PHONE,this);
ApplicationMenuItemRepository.getInstance().removeMenuItem(ApplicationMenuItemRepository.MENUITEM_ADDRESSCARD_VIEW,this);
}
}

 

 

Please use plain text.
Administrator
MSohm
Posts: 14,362
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: How to pull the phone number from addrebooklist / addressbook view context?

This example should help.

 

Access Address Book contacts

http://supportforums.blackberry.com/t5/Java-Development/Access-Address-Book-contacts/ta-p/445045

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
Please use plain text.