tag:blogger.com,1999:blog-72386855013225666.post5574874076817854224..comments2023-04-18T05:16:02.299-04:00Comments on Simon Mac Donald: Saving Contacts with PhoneGap AndroidSimon MacDonaldhttp://www.blogger.com/profile/14749383583517044214noreply@blogger.comBlogger62125tag:blogger.com,1999:blog-72386855013225666.post-27049388416572097452013-08-13T12:45:13.455-04:002013-08-13T12:45:13.455-04:00@Abir
Use the full path to your image and it shou...@Abir<br /><br />Use the full path to your image and it should be okay.Simon MacDonaldhttps://www.blogger.com/profile/14749383583517044214noreply@blogger.comtag:blogger.com,1999:blog-72386855013225666.post-61348255206592682082013-08-13T03:37:30.121-04:002013-08-13T03:37:30.121-04:00Good morning Simon,
This is the code:
var contact...Good morning Simon,<br />This is the code:<br /><br />var contact = navigator.contacts.create();<br /><br />// Contact Photos<br />var photos = [];<br /> <br />var ImgUrl="images/Thomas.jpg";<br /> <br />photos[0] = new ContactField('url', ImgUrl,true);<br />contact.photos = photos;Abirhttps://www.blogger.com/profile/09347373459458403184noreply@blogger.comtag:blogger.com,1999:blog-72386855013225666.post-12059141659521183562013-08-12T10:46:50.689-04:002013-08-12T10:46:50.689-04:00@Abir
Show your code, I'm not sure I understa...@Abir<br /><br />Show your code, I'm not sure I understand what you are asking.Simon MacDonaldhttps://www.blogger.com/profile/14749383583517044214noreply@blogger.comtag:blogger.com,1999:blog-72386855013225666.post-74559848920446964202013-08-12T10:46:04.037-04:002013-08-12T10:46:04.037-04:00How can i save contact photo ? I've passed the...How can i save contact photo ? I've passed the local URL wich point to the image folder in my app but it doesn't work :(<br /><br />Thanks a lotAbirhttps://www.blogger.com/profile/09347373459458403184noreply@blogger.comtag:blogger.com,1999:blog-72386855013225666.post-74453408271237869812013-07-18T03:09:51.084-04:002013-07-18T03:09:51.084-04:00Ok, Thanks! I'll try!Ok, Thanks! I'll try!Anonymoushttps://www.blogger.com/profile/01879175604722475946noreply@blogger.comtag:blogger.com,1999:blog-72386855013225666.post-2845937640093589952013-07-18T00:16:46.264-04:002013-07-18T00:16:46.264-04:00@Pieterjan De Feyter
Yes, I've seen this befo...@Pieterjan De Feyter<br /><br />Yes, I've seen this before. The error callback is invoked because the contact has not yet synced with Googles services. If you won't have the ID at that point you should do a search for the contact by name to get the ID.Simon MacDonaldhttps://www.blogger.com/profile/14749383583517044214noreply@blogger.comtag:blogger.com,1999:blog-72386855013225666.post-16274356039338420442013-07-17T09:42:07.805-04:002013-07-17T09:42:07.805-04:00Hey Simon,
Your article helps big time!
The only ...Hey Simon,<br /><br />Your article helps big time!<br />The only problem I have is that on a real phone, although the contact is getting saved, it still calls "onSaveError". And that's a pitty, because I am trying to save contacts and keep their id's stored in an other file so I could be able to easily remove them later on. (I want to work with id's because their could be multiple "John Johnsons" as a person).<br />On the simulator, I could easily get the ID in the "onSaveSuccess" by calling contact.id, but on a real device it saves but doesn't run "OnSaveSucces".<br /><br />Any ideas where the problem could be?<br /><br />Thanks<br /><br />PieterjanAnonymoushttps://www.blogger.com/profile/01879175604722475946noreply@blogger.comtag:blogger.com,1999:blog-72386855013225666.post-61663318976649897802013-06-25T16:00:36.514-04:002013-06-25T16:00:36.514-04:00@Pawel G
It's is interesting that it works o...@Pawel G <br /><br />It's is interesting that it works on the emulator. Have you tried seeing what "adb logcat" reports when you try it on the device?Simon MacDonaldhttps://www.blogger.com/profile/14749383583517044214noreply@blogger.comtag:blogger.com,1999:blog-72386855013225666.post-15011706160354693972013-06-18T10:54:39.400-04:002013-06-18T10:54:39.400-04:00@Simon MacDonald
Now have another problem with re...@Simon MacDonald<br /><br />Now have another problem with remove contact...<br />Before "repair" update contact function, remove was working fine like this:<br /><br />var contact = navigator.contacts.create({<br />id: id<br />});<br />contact.remove(function(){<br />//...<br />},function(error){<br />//error<br />});<br /><br />After change update contact code its not work, so i change this like update contakt code to:<br /><br />var options = new ContactFindOptions();<br />options.filter=id;<br />options.multiple=false;<br />var fields = ["id", "displayName", "name", "nickname", "phoneNumbers", "photos", "emails", "addresses", "ims", "organizations", "birthday", "note", "categories", "urls"];<br />navigator.contacts.find(fields, function(contacts) {<br />if(typeof(contacts[0]) !== "undefined" && contacts[0] !== null)<br />alert(contacts[0].id);<br />contacts[0].remove(function(){<br />//...<br />},function(error){<br />alert(error.code);<br />})}, function(error){<br />alert(error.code)}, options);<br /><br />And it's not work, i get error.code = 0 from remove()<br />What is wrong with my code?<br /><br />PS. it work on emulator but not on real device and i have no any app - what sugest @Javier Gil RomeroAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-72386855013225666.post-50331707440188474082013-06-17T09:19:03.400-04:002013-06-17T09:19:03.400-04:00@Simon MacDonald
Thanks so much, it's work no...@Simon MacDonald<br /><br />Thanks so much, it's work now!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-72386855013225666.post-14095687483003987972013-06-14T11:39:38.604-04:002013-06-14T11:39:38.604-04:00@Pawel G
If you want to updated an existing cont...@Pawel G <br /><br />If you want to updated an existing contact you should do a navigator.contacts.find and in that success call you would modify the contacts attributes and then call contact.save(). Don't create a new contact and try to match the ID's.Simon MacDonaldhttps://www.blogger.com/profile/14749383583517044214noreply@blogger.comtag:blogger.com,1999:blog-72386855013225666.post-85546180184436043772013-06-14T10:59:23.638-04:002013-06-14T10:59:23.638-04:00@Simon MacDonald
I have same problem like Javier ...@Simon MacDonald<br /><br />I have same problem like Javier Velez...<br /><br />java.lang.NumberFormatException: unable to parse 'null' as integer<br /><br />when i try set id and update contact:<br /><br />contact = navigator.contacts.create({<br /> id: model.contact.list[id].id,<br /> displayName: displayName,<br /> name: namex,<br /> nickname: nickname,<br /> organizations: organizations,<br /> photos: contactImgs,<br /> phoneNumbers: contactPhoneNumbers,<br /> note: note<br /> });<br /> contact.save(function(result){<br />//some staff...<br /> },function(error){<br /> console.log('save' + error.code)<br /> });<br /><br />please help!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-72386855013225666.post-77762186390561042552013-05-29T08:02:32.894-04:002013-05-29T08:02:32.894-04:00@Mallikarjun C H
If you follow this post it descr...@Mallikarjun C H<br /><br />If you follow this post it describes how to setup a new account. To check to see if there is already an account setup you just need to look at the Accounts section of the Contacts app.Simon MacDonaldhttps://www.blogger.com/profile/14749383583517044214noreply@blogger.comtag:blogger.com,1999:blog-72386855013225666.post-61287935648441900822013-05-29T05:25:59.623-04:002013-05-29T05:25:59.623-04:00Hi thanks for your good article.
How to check weat...Hi thanks for your good article.<br />How to check weather google(gmail) account added in emulator or not?<br />please replyMallikarjun C Hhttps://www.blogger.com/profile/06196751147066601593noreply@blogger.comtag:blogger.com,1999:blog-72386855013225666.post-5161168443643155872013-04-12T04:59:38.907-04:002013-04-12T04:59:38.907-04:00Hello everyone!
I was trying to get rid of and er...Hello everyone!<br /><br />I was trying to get rid of and error with the PG contact API.<br /><br />I followed the API Doc instructions, but kept getting "error = 0" when I save a contact.<br /><br />I figured out that the contact actually saves as a "hotmail contact", so after i removed the Hotmail app from my phone, the code worked fine.<br /><br />Maybe any other "contact manager" application interfere like the hotmail one.<br /><br />Hope it helps someone.AnAkiNJavihttps://www.blogger.com/profile/00486148524098832850noreply@blogger.comtag:blogger.com,1999:blog-72386855013225666.post-60716042120055593982013-02-02T17:29:07.263-05:002013-02-02T17:29:07.263-05:00@Javier Velez
Can you post some code that reprodu...@Javier Velez<br /><br />Can you post some code that reproduces the bug? I have a feeling I may know what is going on but I'd like to see your code to make sure I have the right case. Another dev added some code to verify that the right data types were being passed in.Simon MacDonaldhttps://www.blogger.com/profile/14749383583517044214noreply@blogger.comtag:blogger.com,1999:blog-72386855013225666.post-71592683117629425052013-02-02T13:30:25.166-05:002013-02-02T13:30:25.166-05:00Hi Simmon,
Thanks for your excellent article. ...Hi Simmon,<br /><br /> Thanks for your excellent article. We have an issue with contact.save in Android. In iOS works fine, but since we update to cordova 2.3, when we try to save a new contact show the followe error (Eclipse - LogCat): <br /><br />Tag: ContactsAccessor<br />Text: org.apache.cordova.ContactAccessor 147 rawId is string called 'null'<br /><br /><br />and:<br /><br />Tag: AndroidRuntime<br />Text: java.lang.NumberFormatException: unable to parse 'null' as integer<br /><br /> We try to set Id integer value to contact and no works.<br /><br /> The same code works so fine in iOS but no works in Android.<br /><br /> This is a bug or we are doing the wrong things?<br /><br /> Thanks! Best regards!!!<br /><br />Javier!Anonymoushttps://www.blogger.com/profile/08815670309847514899noreply@blogger.comtag:blogger.com,1999:blog-72386855013225666.post-46319659426183324432012-08-09T10:34:33.168-04:002012-08-09T10:34:33.168-04:00@sangeeth_LVS
Since people want this feature can ...@sangeeth_LVS<br /><br />Since people want this feature can you raise a ticket on JIRA? If you and @Vasanth comment on it then it will have more weight.<br /><br />https://issues.apache.org/jira/browse/CBSimon MacDonaldhttps://www.blogger.com/profile/14749383583517044214noreply@blogger.comtag:blogger.com,1999:blog-72386855013225666.post-1769751717190167392012-08-09T10:32:32.987-04:002012-08-09T10:32:32.987-04:00@Vasanth
The W3C does not specific a way to set w...@Vasanth<br /><br />The W3C does not specific a way to set what account the contact will be saved in. We start by looking for email accounts and if we don't find any we then default to the phone itself.Simon MacDonaldhttps://www.blogger.com/profile/14749383583517044214noreply@blogger.comtag:blogger.com,1999:blog-72386855013225666.post-28636192313009971672012-08-01T02:21:58.118-04:002012-08-01T02:21:58.118-04:00Hi Simon,
How can i save a contacts to the pho...Hi Simon,<br /> How can i save a contacts to the phone's local memory and in google contacts.<br /><br />Thanks..<br /><br />kumar.Anonymoushttps://www.blogger.com/profile/10052664094894768235noreply@blogger.comtag:blogger.com,1999:blog-72386855013225666.post-52488264052963919482012-08-01T01:57:27.550-04:002012-08-01T01:57:27.550-04:00hi simon,
did u find the solution for saving the ...hi simon,<br /><br />did u find the solution for saving the contact in local device,instead of saving it in to the google contatcs or is there any possiblity to raise a prompt box asking as to save in local or in google contacts (as in google android API).<br /><br />Thanks in Advance ...sangeeth_LVShttps://www.blogger.com/profile/15465143137121947693noreply@blogger.comtag:blogger.com,1999:blog-72386855013225666.post-9010932115971436312012-07-25T09:02:50.579-04:002012-07-25T09:02:50.579-04:00@SimpleSolution
Yes@SimpleSolution<br /><br />YesSimon MacDonaldhttps://www.blogger.com/profile/14749383583517044214noreply@blogger.comtag:blogger.com,1999:blog-72386855013225666.post-10949969132340792582012-07-25T07:15:42.392-04:002012-07-25T07:15:42.392-04:00@Simon
Instead of phonegap.js, do we now us cord...@Simon <br /><br />Instead of phonegap.js, do we now us cordova.js file?SimpleSolutionhttps://www.blogger.com/profile/00624223779494653281noreply@blogger.comtag:blogger.com,1999:blog-72386855013225666.post-70483515309482986382012-07-22T20:59:08.509-04:002012-07-22T20:59:08.509-04:00@Bo Wen
It has to do with the syncing of the cont...@Bo Wen<br /><br />It has to do with the syncing of the contact with Google. It returns an error since the contact hasn't finished syncing yet. There is an open bug on this issue I have not been able to get to yet.Simon MacDonaldhttps://www.blogger.com/profile/14749383583517044214noreply@blogger.comtag:blogger.com,1999:blog-72386855013225666.post-73645869160438069892012-07-22T17:39:13.670-04:002012-07-22T17:39:13.670-04:00Hi Simon,
Thank you for this great instruction!
...Hi Simon,<br /><br />Thank you for this great instruction!<br /><br />I met a strange problem with the call back function. Most of the time, the contact.save() will call the error callback with code 0. In one out of 20 chances, it will call the success callback, but 'console.log("Success="+JSON.stringify(contact));' shows that the returned contact object is another person on my phonebook rather than the one I created just now. The app is built with PG 1.7.0, upgrading to 1.8.1 didn't solve the problem. I am testing it on Samsung galaxy s2 with Android OS 4.0.4. Apperantly another person also got similar question on Android OS 2.3.3 in this thread: https://groups.google.com/d/msg/phonegap/O0nrdrDyieE/8IaSwYdDP-8J<br /><br />Can you give us some suggestions on this problem? Thank you!Anonymousnoreply@blogger.com