Add a simple contact with a name and a phone number
This is a code adding a basic contact with name, surname and phone number.
PRIVILEGE NEEDED: http://tizen.org/privilege/contact.write
// PRIVILEGE needed to be set in tizen-manifest.xml:
// http://tizen.org/privilege/contact.write
#include <contacts.h>
#include <dlog.h> // for logging purposes
contacts_record_h contact;
contacts_record_h contact_name;
contacts_record_h contact_number;
int id=0;
if (contacts_connect() == CONTACTS_ERROR_NONE)
{
// Creating contact.
// Replace name, surname and phone number with your data.
if (contacts_record_create(_contacts_contact._uri, &contact) == CONTACTS_ERROR_NONE
&& contacts_record_create(_contacts_name._uri, &contact_name) == CONTACTS_ERROR_NONE
&& contacts_record_set_str(contact_name, _contacts_name.first, "Insert_name") == CONTACTS_ERROR_NONE
&& contacts_record_set_str(contact_name, _contacts_name.last, "Insert_surname") == CONTACTS_ERROR_NONE
&& contacts_record_add_child_record(contact, _contacts_contact.name, contact_name) == CONTACTS_ERROR_NONE
&& contacts_record_create(_contacts_number._uri, &contact_number) == CONTACTS_ERROR_NONE
&& contacts_record_set_str(contact_number, _contacts_number.number, "+000000000") == CONTACTS_ERROR_NONE
&& contacts_record_add_child_record(contact, _contacts_contact.number, contact_number) == CONTACTS_ERROR_NONE)
{
LOGI ("Contact created!");
if (contacts_db_insert_record(contact, &id) == CONTACTS_ERROR_NONE)
{
LOGI("Contact inserted to database. Contact id: %d", id);
}
}
if (contacts_disconnect() == CONTACTS_ERROR_NONE)
{
LOGI ("Disconnected from contacts service!");
}
}