Unable to access contact list


#1

I’m trying to access the phone contact list, and for the life of me, I can’t seem to get the navigation.contacts to actually have a value. Here’s the code I’m working with inside of my controller:

$ionicPlatform.ready(function () {
// called when ready
alert(“Device ready”);

    function get_contacts() {
        var obj = new ContactFindOptions();
        obj.filter = "";
        obj.multiple = true;

        console.log("navigator.contacts: " + navigator.contacts);
        navigator.contacts.find(["displayName", "name", "phoneNumbers"], contacts_success, contacts_fail, obj);
    }
    function contacts_success(contacts) {
        console.log("contacts_success(): " + JSON.stringify(contacts));
    }
    function contacts_fail(msg) {
        console.log("get_contacts() Error: " + msg);
    }

    get_contacts();

});

The latest error I’m getting is that ContactFindOptions is not defined. I’ve installed the org.apache.cordova.contacts.ContactManager plugin, but still can’t seem to get anything. Anyone have any advice???


#2

After removing the android platform and re-adding the plugin, things just started working.


#3

I tried this too but Im getting this error:

$ ionic plugin add org.apache.cordova.contacts
Fetching plugin "org.apache.cordova.contacts" via plugin registry
Installing "org.apache.cordova.contacts" for android
Error during processing of action! Attempting to revert...
$

Consequently, contacts API fails to get included in the app.


#4