08-19-2010 11:12 AM
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.PhoneCallL og)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_PHONE LOG_VIEW,this);
ApplicationMenuItemRepository.getInstance().addMenuItem(ApplicationMenuItemRepository.MENUITEM_PHONE ,this);
ApplicationMenuItemRepository.getInstance().addMenuItem(ApplicationMenuItemRepository.MENUITEM_ADDRE SSCARD_VIEW,this);
}
// UN-Register the instance of the menuItem with the system
public void unRegisterInstance() {
ApplicationMenuItemRepository.getInstance().removeMenuItem(ApplicationMenuItemRepository.MENUITEM_PH ONELOG_VIEW,this);
ApplicationMenuItemRepository.getInstance().removeMenuItem(ApplicationMenuItemRepository.MENUITEM_PH ONE,this);
ApplicationMenuItemRepository.getInstance().removeMenuItem(ApplicationMenuItemRepository.MENUITEM_AD DRESSCARD_VIEW,this);
}
}
08-23-2010 11:26 AM
This example should help.
Access Address Book contacts
http://supportforums.blackberry.com/t5/Java-Develo