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

Native Development

Reply
Highlighted
Developer
Posts: 61
Registered: ‎10-16-2013
My Device: Z10
My Carrier: vodaphone
Accepted Solution

ContactService returns empty contact list

Hello people!

I need to get all the contacts that are there in the phone contacts.

https://developer.blackberry.com/native/reference/cascades/bb__pim__contacts__contactservice.html#fu...

the code snippet here returns empty contact list!

help!!

Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: ContactService returns empty contact list

did you set the permission in the bar descriptor?
----------------------------------------------------------
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: 61
Registered: ‎10-16-2013
My Device: Z10
My Carrier: vodaphone

Re: ContactService returns empty contact list

yes i did!! 

Solved it myself.. used the address book sample app, following code spinnet worked for me..

 

_service = new ContactService(this) ;
QList<Contact> contacts;
// No filter has been specified, so just list all contacts
ContactListFilters filter;
contacts = _service->contacts(filter);

// Iterate over the list of contact IDs
foreach (const Contact &idContact, contacts)
{
// Fetch the complete details for this contact ID
const Contact contact = _service->contactDetails(idContact.id());
qDebug() << contact.firstName() ;

// Copy the data into a model entry
QVariantMap entry;
entry["contactId"] = contact.id();
entry["firstName"] = contact.firstName();
entry["lastName"] = contact.lastName();

const QList<ContactAttribute> emails = contact.emails();
if (!emails.isEmpty())
entry["email"] = emails.first().value();
}