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
samieaji
Posts: 6
Registered: ‎08-29-2012
My Device: Bold 9900

How to get Contacts from blackberry phonebook

[ Edited ]

Hi Everyone,

 

I'm creating an application that requires a user to choose a phone number(could be more than one) from the addressbook, to send a message to the person. Please how do I go about it. I want to open all the contacts in the phonebook, so that a user can choose one or more contacts, with a checkbox by the side

 

Thanks in advance

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

Re: How to get Contacts from blackberry phonebook

New Developer
samieaji
Posts: 6
Registered: ‎08-29-2012
My Device: Bold 9900

Re: How to get Contacts from blackberry phonebook

Ok thx... Lemme check it out
New Developer
samieaji
Posts: 6
Registered: ‎08-29-2012
My Device: Bold 9900

Re: How to get Contacts from blackberry phonebook

Good day , I've looked at both articles and it seems to solve the problem, but I'm having problems putting them together to achieve what I want to do. Please can you help me put them together to give a solution to what I am looking for. I'll be most grateful.

 

Thanks in advance...

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

Re: How to get Contacts from blackberry phonebook

I can help with direction but the actual coding is up to you.

 

The trickiest part of this process is the ListField.  Unfortunately there is not really a single simple example of ListField because it can actually be implemented in a number of way, in fact the way i do it is not the same as any sample.  Given this, you really need to review a ListField and understand how to supply data to it.  So start by focusing on getting a ListField to display the way you want it to.

 

The sample I referenced is OK though it is complicated by the check box coding.  But review that, concentrate on the drawListRow() method and figure out how that works.  That is the key to ListField. 

 

Once you have ListField sorted, then the process of extracting the contacts and adding each contact as a row in the ListField will be easy.

 

Sorry I can't help more. 

Developer
alishaik786
Posts: 285
Registered: ‎08-26-2011
My Device: 9900

Re: How to get Contacts from blackberry phonebook

[ Edited ]

I think the below code will help you:

 

In this you get

 

 

1. A Vector list having number of HashTable of each contact list details. 

2. In this HashTable you will get another HashTable which contains Number of Contacts(Like WORK, HOME, MOBILE) etc.

 

Check the below code:

 

See the Highlighted to get an idea. 

 

public static Vector contactsVector;

public void getAllContactLists() 
{
	try 
	{
		BlackBerryContactList blackBerryContactList = (BlackBerryContactList)PIM.getInstance().openPIMList(PIM.CONTACT_LIST,PIM.READ_ONLY);
		Enumeration er = blackBerryContactList.items();			
		contactsVector=new Vector(blackBerryContactList.size());
		while(er.hasMoreElements())
		{
			Hashtable contactHash=new Hashtable();
			BlackBerryContact blackBerryContact = (BlackBerryContact)er.nextElement();
			//System.out.println("================EMAIL: "+blackBerryContact.getString(BlackBerryContact.EMAIL, 0)+"\n");
			String[] name = blackBerryContact.getStringArray(BlackBerryContact.NAME, 0);
			String contactName="";
			
			contactName=name[BlackBerryContact.NAME_GIVEN]!=null ? name[BlackBerryContact.NAME_GIVEN] : "";
			contactName=name[BlackBerryContact.NAME_FAMILY]!=null ? contactName+" "+name[BlackBerryContact.NAME_FAMILY] : contactName;
			contactHash.put("CONTACT_NAME", contactName.trim());
			
			String emailAddress=(blackBerryContact.countValues(BlackBerryContact.EMAIL)>0)? blackBerryContact.getString(BlackBerryContact.EMAIL, 0) : "" ;
	
			int numOfPhones=blackBerryContact.countValues(BlackBerryContact.TEL);
			Hashtable phoneNumberHash=new Hashtable();
			for(int i=0;i<numOfPhones;i++)
			{
				if(blackBerryContact.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_WORK )
					phoneNumberHash.put("WORK", blackBerryContact.getString(BlackBerryContact.TEL, i));
				if(blackBerryContact.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_HOME)
					phoneNumberHash.put("HOME", blackBerryContact.getString(BlackBerryContact.TEL, i));
				if(blackBerryContact.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_MOBILE)
					phoneNumberHash.put("MOBILE", blackBerryContact.getString(BlackBerryContact.TEL, i));											
			}
			
			contactHash.put("EMAIL", emailAddress);
			if("".equals(contactHash.get("CONTACT_NAME")))
				contactHash.put("DISPLAY_NAME", "UnKnown Number");
				
			if(phoneNumberHash.containsKey("WORK")|| phoneNumberHash.containsKey("HOME") || phoneNumberHash.containsKey("MOBILE"))
			{
				contactHash.put("PHONE_NUMBER", phoneNumberHash);
				contactsVector.addElement(contactHash);
			}
		}			
	}
	catch (Exception e) 
	{	
		if(e!=null)
			StartUp.errorHandling("Exception: "+e.getMessage());			
	}
}

If you have any doubts let me know.

 

 

 

=================================================================================
Feel free to click LIKE button if the solution helps you;
--
Regards,

ALI SHAIK.