Error saving contact on Android

2,055 views
Skip to first unread message

Duncan Krebbers

unread,
Nov 20, 2011, 1:59:43 PM11/20/11
to phonegap
Based on the code examples I'm trying to create a new contact on an
Android-phone.

because not everything is documented for saving a contact (mostly only
finding contacts is documented)

This is what I have so far; it saves a contact on my phone, but gives
an error (errorcode 0).

The url is not saved, the rest seems to work.

What am I doing wrong? What can be done better? and can somebody help
me with adding a picture to the contact?

Thanks!

var contact = navigator.contacts.create();
contact.displayName = "Companyname";
contact.nickname = "Companyname";
var phoneNumbers = [2];
phoneNumbers[0] = new ContactField('work', 'phonenumber1', false);
phoneNumbers[1] = new ContactField('mobile', 'phonenumber2', true);
contact.phoneNumbers = phoneNumbers;
var emails = [3];
emails[0] = new ContactField('work', email1', true);
emails[1] = new ContactField('home', 'email2', false);
emails[2] = new ContactField('home', 'email3', false);
contact.emails = emails;
var addresses = [1];
var address = new ContactAddress();
address.type = 'work';
address.streetAddress='Streetname';
address.locality='City';
address.postalCode = 'postalcode';
address.country='country';
addresses[0] = address;
contact.addresses = addresses;
var organizations = [1];
var organization = new ContactOrganization();
organization.type = 'work';
organization.name='Companyname';
organizations[0] = organization;
contact.organizations = organizations;
var urls = [1];
urls[0] = new ContactField('work', 'http://mywebsite.nl',false);
contact.urls = urls;
// save
contact.save(onSaveSuccess,onSaveError);

Simon MacDonald

unread,
Nov 23, 2011, 2:24:26 PM11/23/11
to phon...@googlegroups.com
Hey Duncan,

Read my post on this and let me know if you still have an issue saving a contact.


Simon Mac Donald
http://hi.im/simonmacdonald



--
You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en

For more info on PhoneGap or to download the code go to www.phonegap.com

Reply all
Reply to author
Forward
0 new messages