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 Contributor
geraud
Posts: 3
Registered: ‎12-08-2010
My Device: Not Specified

Finding a Contact, given a Phone Number

Hello,

I am using sdk 5.0. I'm overriding

AbstractPhoneListener.callInitiated(int callID)

and I am trying to use this callID to find all BlackberryContacts with a matching phone number. The problem is that

Phone.getCall(callId).getPhoneNumber()

returns a string like "+12345678901", whereas a number stored under one of the attributes in the

Contact.TEL

field can have a user-formatted string, like "(234)567-8901". Is there a good way to search a phone number or a standard way to normalize the phone numbers in the Contact before doing a compare? I've tried both

PhoneCallLogID.getNumber()

and

PhoneCallLogID.getAddressBookFormattedNumber()

on both the Listener's phone number and the Contact's phone numbers, but both of these functions return the same number used in the constructor. Also, I cant use

Phone.getContactByPhoneNumber(...)

or

BlackberryContactList.itemsByPhoneNumber(...)

because I am using sdk 5.0, not 6.0. Any help is appreciated.

Please use plain text.
Developer
nitinverma274
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: Finding a Contact, given a Phone Number

Welcome to the Forum,

 

Read carefully about this Article.

 

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

 

Hope this Help.

------------------------------------------------------------------------------------
Press Kudo to say thank to developer.
Also Press the Accept as solution Button when u got the Solution.

Please use plain text.
New Contributor
geraud
Posts: 3
Registered: ‎12-08-2010
My Device: Not Specified

Re: Finding a Contact, given a Phone Number

I understand how to iterate through the fields/attributes in a Contact, however this doesn't help me with discrepancies in the two phone numbers. I read through the code in that article and don't see anything relevant. Is there a line I missed that you can point me to?

Please use plain text.
Developer
vivart
Posts: 147
Registered: ‎08-27-2010
My Device: 9800
My Carrier: airtel

Re: Finding a Contact, given a Phone Number

perhaps  this solution will be a overhead but it will work.

 

 

public static String stripSpecialChars(String number){
		char[] chars = number.toCharArray();
		StringBuffer sb = new StringBuffer();
		
		for (int i = 0; i < chars.length; i++) {
			if(Character.isDigit(chars[i])){
				sb.append(chars[i]);
			}
		}
		return sb.toString();
		
	}

 

call this method on both numbers before compare.

 

Please use plain text.
Developer
nitinverma274
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: Finding a Contact, given a Phone Number

[ Edited ]

Ok you want to do that you have a phone number and match that number in the contact list and get the Contact name right.

 

Edit : If you have compare problem then I think @vivart is right.

------------------------------------------------------------------------------------
Press Kudo to say thank to developer.
Also Press the Accept as solution Button when u got the Solution.

Please use plain text.
New Contributor
geraud
Posts: 3
Registered: ‎12-08-2010
My Device: Not Specified

Re: Finding a Contact, given a Phone Number

Yes, I was considering this solution and then comparing only last 10 digits (to ignore country code because the country code shows up in the Phone call ID, but not necessarily in the Contact). Was hoping for a more standard solution, but I guess this will have to do. Thanks for your inputs.

Please use plain text.
Developer
simon_hain
Posts: 15,942
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Finding a Contact, given a Phone Number

you can use a small backdoor to get the name matching a number.

create a http://www.blackberry.com/developers/docs/6.0.0api/net/rim/blackberry/api/phone/phonelogs/PhoneCallL... instance and call getName. If the number matches one of the contacts in the addressbook (using RIMs internal algorithm) you will get the name.

using the full name you can do a much quicker local search, iterating through the addressbook is not doable as it is very(!) slow. an addressbook with 1k contacts will take several minutes to iterate.

----------------------------------------------------------
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
Please use plain text.
Developer
vivart
Posts: 147
Registered: ‎08-27-2010
My Device: 9800
My Carrier: airtel

Re: Finding a Contact, given a Phone Number

great i think its the perfect solution.

Please use plain text.