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
Developer
Posts: 16,579
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
Accepted Solution

Get the participant from the current call

I want to get the participant, more precisely the name, from an incoming call (if the number is stored in the local addressbook).
The only way i see to get the name is to look at the call log. It seems that the current call is only added after it is finished though.
It seems not even possible to lookup a number using BlackberryContactList as it takes only names for input.

Any ideas?
----------------------------------------------------------
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
Developer
Posts: 21
Registered: ‎07-16-2008
My Device: Not Specified

Re: Get the participant from the current call

[ Edited ]

Probably not the cleanest since I didn't spend too much time on it, but I think this is what you're looking for:

 

Placed in callConnected method of your phone listener

//incomingcall: static boolean variable set to true during a callIncoming event if(incomingcall) { PhoneCall pc = Phone.getActiveCall(); String number = pc.getDisplayPhoneNumber(); //getDisplayPhoneNumber() method returns a label as well as the number //if caller is a contact, these lines will parse it. number = number.substring(number.indexOf(' ')); number = number.trim(); try{ BlackBerryContactList bbcl = (BlackBerryContactList)PIM.getInstance().openPIMList(PIM.CONTACT_LIST,PIM.READ_ONLY); Enumeration enumerate = bbcl.items(); //iterate through contacts while(enumerate.hasMoreElements()) { Contact c = (Contact)enumerate.nextElement(); PIMList pimlist = c.getPIMList(); int[] intarray = c.getFields(); for(int x = 0; x < intarray.length; x++) { if (pimlist.getFieldDataType(intarray[x]) == PIMItem.STRING) { if(intarray[x] == c.TEL) {

for(int y=0; y < c.countValues(Contact.TEL); y++) { //see if opened contact matches the number if(c.getString(Contact.TEL, y).equals(number)) { //Caller's name stored in namearray String[] namearray = c.getStringArray(Contact.NAME,0); } } } } } } } catch(PIMException e) {} incomingcall = false;

 

EDIT:  Also keep in mind this is probably not very efficient since it will iterate through EVERY number of EVERY contact.

Another thing to note is that some fields(work2, home2) were not supported and cannot be accessed until 4.5 so if the number is stored in those fields, you can't get the name of the contact through this method.

Message Edited by PaoloLim on 07-31-2008 11:06 AM
Message Edited by PaoloLim on 07-31-2008 11:17 AM
Developer
Posts: 16,579
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Get the participant from the current call

this is a possibility i have not taken until now due to performance issues. i'll have to test it on a phone with several hundred phonebook entries to see if it is usable.
seems to be the only way :smileysad:

thanks for reminding me about this approach, i'll mark the thread as solved.
----------------------------------------------------------
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: 31
Registered: ‎07-06-2009
My Device: Not Specified

Re: Get the participant from the current call

number = number.substring(number.indexOf(' '));

number = number.trim();

 

gave me an exception....

please help 

Developer
Posts: 16,579
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Get the participant from the current call

the code is not very safe. indexof returns -1 if the string is not found, this should be checked.
you can also check for number being null.

for further reference: "gave me an exception" is not a very helpful description.
----------------------------------------------------------
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