Languages

Menu
Sites
Language
Restore contact from vcard

i have converted contact to vcard . now i want to add that vcard to contacts

textual representation of the contact is: BEGIN:VCARD VERSION:3.0 N;CHARSET=UTF-8:John;Elton;;; FN;CHARSET=UTF-8:Elton John TEL;TYPE=VOICE;PREF;CHARSET=UTF-8:987654321 EMAIL;TYPE=WORK;PREF;CHARSET=UTF-8:user2@domain.com NICKNAME;CHARSET=UTF-8:El REV:2015-02-06T10:58:19Z END:VCARD

 

how i can add to my addressbook ? any api present ?

Responses

16 Replies
Alex Dem

Hi,
Maybe you could use this:
https://developer.tizen.org/dev-guide/2.3.0/org.tizen.mobile.web.appprogramming/html/tutorials/social_tutorial/import_contacts.htm
Alexey.

 

appdaily

so i have to manully split string from vcard which i have and then add?

Marco Buettner

All you need is to read your vcard as string.

appdaily

            contact = new tizen.Contact("BEGIN:VCARD                    VERSION:3.0                    N;CHARSET=UTF-8:Hyman;Jeffrey;;;                    FN;CHARSET=UTF-8:Jeffrey Hyman                    TEL;TYPE=VOICE;PREF;CHARSET=UTF-8:123456789                    EMAIL;TYPE=WORK;PREF;CHARSET=UTF-8:user1@domain.com                    NICKNAME;CHARSET=UTF-8:joey ramone                    REV:2015-02-09T07:08:58Z                    END:VCARD");

addressbook.add(contact);
 this giving me unknow error

AVSukhov

Hello,

I have tested your code and it`s work fine:

contact = new tizen.Contact("BEGIN:VCARD\n"+
       "VERSION:3.0\n"+
       "N;CHARSET=UTF-8:Hyman;Jeffrey;;;\n"+
       "FN;CHARSET=UTF-8:Jeffrey Hyman\n"+
       "TEL;TYPE=VOICE;PREF;CHARSET=UTF-8:123456789\n"+
       "EMAIL;TYPE=WORK;PREF;CHARSET=UTF-8:user1@domain.com\n"+
       "NICKNAME;CHARSET=UTF-8:joey ramone\n"+
       "REV:2015-02-09T07:08:58Z\n"+
       "END:VCARD");

addressbook.add(contact);

verify that you add necessary privilege in config.xml

appdaily

with this its working ,do we need \n? how i can get total contacts in addressbook?

AVSukhov

Hello,

You can use find() method of AddressBook intreface to finds an array of all Contact objects from the specified address book or an array of Contact objects that match the optionally supplied filter.

appdaily
contact = new tizen.Contact("BEGIN:VCARD VERSION:3.0 N;CHARSET=UTF-8:Hyman;Jeffrey;;; FN;CHARSET=UTF-8:Jeffrey Hyman TEL;TYPE=VOICE;PREF;CHARSET=UTF-8:123456789  "EMAIL;TYPE=WORK;PREF;CHARSET=UTF-8:user1@domain.com "NICKNAME;CHARSET=UTF-8:joey ramone "REV:2015-02-09T07:08:58Z    "END:VCARD"); 
addressbook.add(contact);

this adding contact but it adding as unknow with all blank value

John Ixion

If your interested, this is great PIM software: https://syncevolution.org/

appdaily

can we get vcard in this format

BEGIN:VCARD
VERSION:3.0
N:Gump;Forrest;;Mr.
FN:Forrest Gump
ORG:Bubba Gump Shrimp Co.
TITLE:Shrimp Man
PHOTO;VALUE=URL;TYPE=GIF:http://www.example.com/dir_photos/my_photo.gif
TEL;TYPE=WORK,VOICE:(111) 555-1212
TEL;TYPE=HOME,VOICE:(404) 555-1212
ADR;TYPE=WORK:;;100 Waters Edge;Baytown;LA;30314;United States of America
LABEL;TYPE=WORK:100 Waters Edge\nBaytown, LA 30314\nUnited States of America
ADR;TYPE=HOME:;;42 Plantation St.;Baytown;LA;30314;United States of America
LABEL;TYPE=HOME:42 Plantation St.\nBaytown, LA 30314\nUnited States of America
EMAIL;TYPE=PREF,INTERNET:forrestgump@example.com
REV:2008-04-24T19:52:43Z
END:VCARD

 

i dont want it in json format

AVSukhov

hello,

When you export contact to Vcard you get result as string.

appdaily

how i can get total contacts from device?

var addressbook = tizen.contact.getDefaultAddressBook();

from addressbook how i can get all contacts length and then convert to vcard

appdaily

i am using follwing

function totalcontacts() {
        var addressbook = tizen.contact.getDefaultAddressBook();
        /*     var as = addressbook.get(1).name; */
             var filter = new tizen.AttributeFilter("name.firstName");
        addressbook.find(contactsFoundCB, errorCB, filter);
    }

    function errorCB(err) {
        console.log('The following error occurred: ' + err.name);
    }

    function contactsFoundCB(contacts) {
        /* Convert the first contact */

        console.log('occurred: ' + contacts.length);
        for (var int = 0; int < contacts.length; int++) {
            var vcard = contacts[int].convertToString("VCARD_30");
            console.log(vcard);
        }
    
    }

 

is this right . this will give me only contacts those having first name can i get all contacts even if they dont have first name

AVSukhov

Hello,

Try to use find() without any filters:

addressbook.find(contactsFoundCB, errorCB);

 

appdaily

for (var int = 0; int < contacts.length; int++) {

// i want var cid = contacts[int]. for this contact can i get id
            var vcard = contacts[int].convertToString("VCARD_30");
            console.log(vcard);
        }

 

in this can i get id for that contact

AVSukhov

Hello,

If using find method from Contact API you will receive array of Contact object. This object has attribute contactId.

And you can use: contact[i].id

For more info please refer to: https://developer.tizen.org/dev-guide/2.3.0/org.tizen.web.apireference/html/device_api/mobile/tizen/contact.html#Contact