Search code examples
androidcordovacontacts

Phonegap Contacts API - Android - return only phone contacts and not gmail contacts


I am using phonegap 2.9.0 to retrieve the contacts list on android and iOS.

As you can see on the screenshot below, I got 67 contacts on the phone + 952 gmail contacts

contacts

The following code returns 1019 contacts. How is it possible to retrieve only the real contacts with the phonegap API?

Is there a group notion in phonegap? I read the documentation but the filter is pretty basic.

    var options      = new ContactFindOptions();
    options.multiple = true;
    var fields       = ["name", "phoneNumbers"];
    navigator.contacts.find(fields, function(contacts) { 
        for (var i = 0; i < contacts.length; i++) {
            console.log("Display Name = " + contacts[i].name.formatted);
            if(contacts[i].phoneNumbers)
              console.log("phone = " + contacts[i].phoneNumbers[0].value);
        }
    }, function(contact_error) { 
      $scope.contact_has_error = true;  
    }, options);

thanks for your help


Solution

  • FYI, I wrote a plugin to return only the contacts with at least one phone numbers. The performances are way better.

    https://github.com/dbaq/cordova-plugin-contacts-phone-numbers