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
Developer
Posts: 246
Registered: ‎09-30-2010
My Device: Z10, Onyx2
My Carrier: IND XL
Accepted Solution

get all contacts

ive try the example of andress book from here

 

http://blackberry.github.io/Cascades-Samples/addressbook.html

 

after i compile and run it on my device not all the contact is showing...

how to get all the contacts on the device?

i have 300 contact only showing 20

Developer
Posts: 246
Registered: ‎09-30-2010
My Device: Z10, Onyx2
My Carrier: IND XL

Re: get all contacts

i know the problem was

ContactSearchFilters filters;
filters.setLimit(0);

need to set the limit for return all the contacts
Retired
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30
My Carrier: Bell

Re: get all contacts

Your best bet is to retrieve them in groups. Many users have thousands of contacts, and there is a limit to how many will actually be returned at once (I think it's actually 200).

 

Also, you won't be able to get the information for Facebook and other social network contacts.

Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker
Developer
Posts: 246
Registered: ‎09-30-2010
My Device: Z10, Onyx2
My Carrier: IND XL

Re: get all contacts

what do you mean retrieve by group?

i use groupCount to check if there is a group but it was return 0.

Retired
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30
My Carrier: Bell

Re: get all contacts

I mean you want to set a limit and retrieve the first X amount of contacts (say, 20), then if you need more, retrieve the next increment. Keep doing that until you don't need more.

Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker
Developer
Posts: 246
Registered: ‎09-30-2010
My Device: Z10, Onyx2
My Carrier: IND XL

Re: get all contacts

[ Edited ]

but how do i know when already reach at the end of contacts?

 

let say if i do it like this

 

ContactListFilters filters;
filters.setLimit(20); ContactService contactService; QList<Contact> contacts = ContactService.contacts(filters);
int startOffset = 21; while(!contacts.isEmpty()) { int size = contacts.size(); if(size != 20) { break; }
filters.setOffset(startOffset);
contacts = ContactService.contacts(filters);
startOffset += 20; }

 if the contacts only have 40. it will never break the loop.

 

PS. my bad... after i test it.. working fine as you suggested...

 

ContactListFilters filters;
    filters.setLimit(20);
    ContactService contactService;
    QList<Contact> contacts = contactService.contacts(filters);
    int startOffset = 21;
    while(!contacts.isEmpty()) {
        int size = contacts.size();
        qDebug() << "CONTACT FOUND " << size;
        for(int i = 0; i < size; i++) {
            Contact contact = contacts.at(i);
            qDebug() << "CONTACT NAME: " << contact.sortFirstName();
        }
        filters.setOffset(startOffset);
        contacts = contactService.contacts(filters);
        startOffset += 20;
    }

 it will return empty when i check here contacts.isEmpty()

 

do ContactSearchFilters have a limit too?

Retired
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30
My Carrier: Bell

Re: get all contacts

Yes, I believe so.

Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker
Highlighted
Developer
Posts: 161
Registered: ‎01-03-2013
My Device: n/a
My Carrier: n/a

Re: get all contacts

You need to use the setAnchorId method:

 

const int LIMIT = 20;
ContactListFilters filters;
filters.setLimit(LIMIT);
ContactService contactService;
QList<Contact> pageOfContacts;
while(true) {
    pageOfContacts = contactService.contacts(filters);
    //do with the contacts received whatever you want
    if(pageOfContacts.size() != LIMIT)
    {
      break;
    }
    filters.setAnchorId(pageOfContacts[LIMIT - 1].id());    
}

 

Regards.

If my answer has been useful to you, please, click the button