Victor
Victor

Reputation: 263

Can't see contacts that was saved with phonegap on android

I'm experience a problem with contacts saving on phonegap(1.9) api.

When I try to save contact on android emulator everything goes just fine, the contact is saved, and I can see it from the contact book.

My problem is to save the contact when I use a device. When I press the buuton to save a contact, onSuccessFunction is fired and I receive the OK message, but when I access the contact book I can't find this contact.

The strange thing is when I dial the number that I want to save, the name of the contact is shown.

I have tried to deploy it on 2 different device (LG Optimus one, android 2.2.1 and Samsug Galaxy 2 , android 2.3.5) and the result is the same.

Please help to solve this issue...

function addContact(emp){

    // create a new contact object
    var contact = navigator.contacts.create();
    //contact.displayName = "Stam";       

    // save First and Last name
    var name = new ContactName();
    name.givenName = emp.firstName;
    name.familyName = emp.lastName;
    contact.name = name;

    // save cell-phone and office-phone
    var phoneNumbers = [];
    phoneNumbers[0] = new ContactField('work', emp.officePhone, false);
    phoneNumbers[1] = new ContactField('mobile', emp.cellPhone, true);
    contact.phoneNumbers = phoneNumbers;

    var emails = [];
    emails[0] = new ContactField('email', emp.email, false); 
    contact.emails = emails;

    var organizations = [];
    organizations[0] = new ContactField('department', emp.department, false);
    organizations[1] = new ContactField('title', emp.title, false);
    contact.organizations = organizations;

        // save contact
        contact.save(onSaveSuccess,onSaveError);
}

// onSaveSuccess: Get a snapshot of the current contacts
function onSaveSuccess(contact) {
    alert("Save Success");
}

// onSaveError: Failed to get the contacts
//
function onSaveError(contactError) {
    alert("Error = " + contactError.code);

}

Upvotes: 2

Views: 1603

Answers (1)

Simon MacDonald
Simon MacDonald

Reputation: 23273

Go into the Contacts app. Click the Menu button and select Display Options. Then you'll need to select the account that you added and click the checkbox to show All Contacts. Typically I set it up to show contacts from all accounts. Then once you click the Done button you'll be taken back to the Contacts application and you will finally get to see the contact you saved.

Upvotes: 3

Related Questions