<li>Tizen 2.4 and Higher for Mobile</li>
<li>Tizen 2.3.1 and Higher for Wearable</li>
</ul>
+ <p class="toc-title">Related Info</p>
+ <ul class="toc">
+ <li><a href="../../../../org.tizen.training/html/native/feature/app_contentshare_n.htm">Creating Applications with Content Sharing</a></li>
+ </ul>
</div></div>
</div>
</ul>
<p class="toc-title">Related Info</p>
<ul class="toc">
- <li><a href="../../../../org.tizen.training/html/native/feature/app_connectivity_n.htm">Creating Applications with Connectivity and Network</a></li>
+ <li><a href="../../../../org.tizen.training/html/native/feature/app_connectivity_n.htm">Creating Applications with Connectivity and Network</a></li>
+ <li><a href="../../../../org.tizen.training/html/native/feature/app_contentshare_n.htm">Creating Applications with Content Sharing</a></li>
</ul>
</div></div>
</div>
<ul class="toc">
<li>Tizen 2.4 and Higher for Mobile</li>
</ul>
+ <p class="toc-title">Related Info</p>
+ <ul class="toc">
+ <li><a href="../../../../org.tizen.training/html/native/feature/app_contacts_n.htm">Creating Applications with Contacts</a></li>
+ </ul>
</div></div>
</div>
<li><a href="native/feature/app_connectivity_p2p_n.htm">P2P Connections with Wi-Fi Direct™</a></li>
</ul>
</li>
+ <li><a href="native/feature/app_contacts_n.htm">Creating Applications with Contacts</a>
+ <ul>
+ <li><a href="native/feature/app_contacts_basic_n.htm">Basic Concepts</a></li>
+ <li><a href="native/feature/app_contacts_management_n.htm">Contact Management</a></li>
+ <li><a href="native/feature/app_contacts_group_n.htm">Group Management</a></li>
+ </ul>
+ </li>
+ <li><a href="native/feature/app_contentshare_n.htm">Creating Applications with Content Sharing</a>
+ <ul>
+ <li><a href="native/feature/app_contentshare_send_n.htm">Sending Content to Other Applications</a></li>
+ <li><a href="native/feature/app_contentshare_receive_n.htm">Receiving Content from Other Applications</a></li>
+ <li><a href="native/feature/app_contentshare_nfc_n.htm">Sharing through NFC</a></li>
+ </ul>
+ </li>
<li><a href="native/feature/app_graphics_n.htm">Creating Applications with Graphics and Animation</a>
<ul>
<li><a href="native/feature/app_graphics_square_n.htm">Squares on the Canvas</a></li>
<p>Demonstrates how you can create applications with connectivity to access various networks to use data services, or connect to other devices.</p>
</li>
+<li><a href="feature/app_contacts_n.htm">Creating Applications with Contacts</a>
+<p>Demonstrates how you can create applications that handle various people-related information, such as contacts, groups, accounts, and address books.</p></li>
+
+<li><a href="feature/app_contentshare_n.htm">Creating Applications with Content Sharing</a>
+<p>Demonstrates how you can create applications with content sharing through application control features or simple NDEF message transfer.</p></li>
+
<li><a href="feature/app_graphics_n.htm">Creating Applications with Graphics and Animation</a>
<p>Demonstrates how you can create applications with graphics and animation to draw various shapes, such as squares and polygons, on the screen and animate screen elements to change their size, position, and color.</p>
</li>
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <meta http-equiv="X-UA-Compatible" content="IE=9" />
+ <link rel="stylesheet" type="text/css" href="../../css/styles.css" />
+ <link rel="stylesheet" type="text/css" href="../../css/snippet.css" />
+ <script type="text/javascript" src="../../scripts/snippet.js"></script>
+ <script type="text/javascript" src="../../scripts/jquery.util.js" charset="utf-8"></script>
+ <script type="text/javascript" src="../../scripts/common.js" charset="utf-8"></script>
+ <script type="text/javascript" src="../../scripts/core.js" charset="utf-8"></script>
+ <script type="text/javascript" src="../../scripts/search.js" charset="utf-8"></script>
+
+ <title>Basic Concepts</title>
+</head>
+
+<body onload="prettyPrint()" style="overflow: auto;">
+
+<div id="toc-navigation">
+ <div id="profile">
+ <p><img alt="Mobile native" src="../../images/mobile_s_n.png"/></p>
+ </div>
+ <div id="toc_border"><div id="toc">
+ <p class="toc-title">Content</p>
+ <ul class="toc">
+ <li><a href="#contacts">Contacts and Persons</a></li>
+ <li><a href="#records">Records and Views</a></li>
+ </ul>
+ <p class="toc-title">Related Info</p>
+ <ul class="toc">
+ <li><a href="../../../../org.tizen.guides/html/native/personal/contacts_n.htm">Contacts Guide</a></li>
+ <li><a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__SOCIAL__CONTACTS__SVC__MODULE.html">Contacts API for Mobile Native</a></li>
+ </ul>
+ </div></div>
+</div>
+<div id="container"><div id="contents"><div class="content">
+<h1>Basic Concepts</h1>
+
+<p>To be able to use contact features in your application, you must first understand how the basic concepts of <strong>contact</strong> and <strong>person</strong> are related, and how the contact information is stored in the Contacts database using records and views.</p>
+
+<h2 id="contacts">Contacts and Persons</h2>
+
+<p>The contact and person are 2 different concepts:</p>
+
+<ul>
+<li><p>A contact object is a collection of information related to a physical person, such as their name, phone numbers, addresses, email addresses, birthday, and organizations. A contact object is always associated with a specific address book. When a contact is successfully added, a contact ID, which is unique within the address book, is given to the contact.</p></li>
+<li><p>A person object is an aggregation of 1 or more contacts associated with the same physical person. A person is created automatically when a contact record is inserted in the Contacts database. A person record cannot be created directly, and every contact must be linked to at least 1 person.</p></li>
+</ul>
+
+<p>The following figure illustrates the contact structure. The example shows 3 instances of the same contact stored in different address books. Person1 is an aggregation of all 3 instances (Contact1, Contact2, and Contact3).</p>
+
+<p class="figure">Figure: Contact structure</p>
+<p align="center"><img alt="Contact structure" src="../../images/app_contacts_contact_structure.png" /></p>
+
+<h2 id="records">Records and Views</h2>
+
+<p>Records and views are important concepts in the Contacts API. Although a record represents an actual record in the internal database, you can consider it a piece of information, like an address, a phone number, or a group of contacts. A record can be a complex set of data, containing other data. For example, an address record contains country, region, and street information.</p>
+
+<p>Records contain properties of basic types:</p>
+<ul>
+<li><span style="font-family: Courier New,Courier,monospace">integer</span></li>
+<li><span style="font-family: Courier New,Courier,monospace">string</span></li>
+<li><span style="font-family: Courier New,Courier,monospace">boolean</span></li>
+<li><span style="font-family: Courier New,Courier,monospace">long integer</span></li>
+<li><span style="font-family: Courier New,Courier,monospace">long long integer</span> (<span style="font-family: Courier New,Courier,monospace">lli</span>)</li>
+<li><span style="font-family: Courier New,Courier,monospace">double</span></li>
+</ul>
+
+<p>The following table lists the functions for setting and getting different record property types.</p>
+
+<table>
+<caption>Table: Functions for specific record property types</caption>
+<tbody>
+<tr>
+ <th>Property type</th>
+ <th>Setter function</th>
+ <th>Getter function</th>
+</tr>
+ <tr>
+ <td><span style="font-family: Courier New,Courier,monospace">string</span></td>
+ <td><span style="font-family: Courier New,Courier,monospace">contacts_record_set_str()</span></td>
+ <td><span style="font-family: Courier New,Courier,monospace">contacts_record_get_str()</span></td>
+ </tr>
+ <tr>
+ <td><span style="font-family: Courier New,Courier,monospace">integer</span></td>
+ <td><span style="font-family: Courier New,Courier,monospace">contacts_record_set_int()</span></td>
+ <td><span style="font-family: Courier New,Courier,monospace">contacts_record_get_int()</span></td>
+ </tr>
+ <tr>
+ <td><span style="font-family: Courier New,Courier,monospace">boolean</span></td>
+ <td><span style="font-family: Courier New,Courier,monospace">contacts_record_set_bool()</span></td>
+ <td><span style="font-family: Courier New,Courier,monospace">contacts_record_get_bool()</span></td>
+ </tr>
+ <tr>
+ <td><span style="font-family: Courier New,Courier,monospace">long long integer</span></td>
+ <td><span style="font-family: Courier New,Courier,monospace">contacts_record_set_lli()</span></td>
+ <td><span style="font-family: Courier New,Courier,monospace">contacts_record_get_lli()</span></td>
+ </tr>
+ <tr>
+ <td><span style="font-family: Courier New,Courier,monospace">double</span></td>
+ <td><span style="font-family: Courier New,Courier,monospace">contacts_record_set_double()</span></td>
+ <td><span style="font-family: Courier New,Courier,monospace">contacts_record_get_double()</span></td>
+ </tr>
+ </tbody></table>
+
+<p>A view is a structure describing the record properties, where the property elements have their data types and names. For example, the <span style="font-family: Courier New,Courier,monospace">_contacts_contact</span> view describes the properties of the contact record, part of which is listed in the following table.</p>
+
+<table>
+<caption>Table: Some contact record properties</caption>
+<tbody>
+<tr>
+ <th>Property ID</th>
+ <th>Type</th>
+ <th>Description</th>
+</tr>
+ <tr>
+ <td><span style="font-family: Courier New,Courier,monospace">uri</span></td>
+ <td><span style="font-family: Courier New,Courier,monospace">string</span></td>
+ <td>Identifier of this contact view</td>
+ </tr>
+ <tr>
+ <td><span style="font-family: Courier New,Courier,monospace">id</span></td>
+ <td><span style="font-family: Courier New,Courier,monospace">integer</span></td>
+ <td>Database record ID of the contact</td>
+ </tr>
+ <tr>
+ <td><span style="font-family: Courier New,Courier,monospace">display_name</span></td>
+ <td><span style="font-family: Courier New,Courier,monospace">string</span></td>
+ <td>Display name of the contact</td>
+ </tr>
+ <tr>
+ <td><span style="font-family: Courier New,Courier,monospace">is_favorite</span></td>
+ <td><span style="font-family: Courier New,Courier,monospace">boolean</span></td>
+ <td><span style="font-family: Courier New,Courier,monospace">boolean</span> value indicating whether the contact is a favorite</td>
+ </tr>
+ <tr>
+ <td><span style="font-family: Courier New,Courier,monospace">name</span></td>
+ <td>Record</td>
+ <td><span style="font-family: Courier New,Courier,monospace">_contacts_name</span> child record containing the contact name details</td>
+ </tr>
+ <tr>
+ <td><span style="font-family: Courier New,Courier,monospace">company</span></td>
+ <td>Record</td>
+ <td><span style="font-family: Courier New,Courier,monospace">_contacts_company</span> child record containing the contact's company details</td>
+ </tr>
+ <tr>
+ <td><span style="font-family: Courier New,Courier,monospace">address</span></td>
+ <td>Record</td>
+ <td><span style="font-family: Courier New,Courier,monospace">_contacts_address</span> child record containing the contact address details</td>
+ </tr>
+ </tbody></table>
+
+<p>Every view has a special field (<span style="font-family: Courier New,Courier,monospace">_uri</span>) that uniquely identifies the view. In many cases, you must provide the <span style="font-family: Courier New,Courier,monospace">_uri</span> value to indicate what type of record you want to operate on. The following example code creates a contact record and obtains the record handle using the <span style="font-family: Courier New,Courier,monospace">_contacts_contact._uri</span> property:</p>
+
+<pre class="prettyprint">
+contacts_record_h contact = NULL;
+
+contacts_record_create(_contacts_contact._uri, &contact);
+</pre>
+
+<script type="text/javascript" src="../../scripts/jquery.zclip.min.js"></script>
+<script type="text/javascript" src="../../scripts/showhide.js"></script>
+</div></div></div>
+
+<a class="top sms" href="#"><img src="../../images/btn_top.gif" alt="Go to top" /></a>
+
+<div id="footer">
+<p class="footer">Except as noted, this content - excluding the Code Examples - is licensed under <a href="http://creativecommons.org/licenses/by/3.0/legalcode" target="_blank">Creative Commons Attribution 3.0</a> and all of the Code Examples contained herein are licensed under <a href="https://www.tizen.org/bsd-3-clause-license" target="_blank">BSD-3-Clause</a>.<br/>For details, see the <a href="https://www.tizen.org/content-license" target="_blank">Content License</a>.</p>
+</div>
+
+<script type="text/javascript">
+var _gaq = _gaq || [];
+_gaq.push(['_setAccount', 'UA-25976949-1']);
+_gaq.push(['_trackPageview']);
+(function() {
+var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+})();
+</script>
+
+</body>
+</html>
+
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <meta http-equiv="X-UA-Compatible" content="IE=9" />
+ <link rel="stylesheet" type="text/css" href="../../css/styles.css" />
+ <link rel="stylesheet" type="text/css" href="../../css/snippet.css" />
+ <script type="text/javascript" src="../../scripts/snippet.js"></script>
+ <script type="text/javascript" src="../../scripts/jquery.util.js" charset="utf-8"></script>
+ <script type="text/javascript" src="../../scripts/common.js" charset="utf-8"></script>
+ <script type="text/javascript" src="../../scripts/core.js" charset="utf-8"></script>
+ <script type="text/javascript" src="../../scripts/search.js" charset="utf-8"></script>
+
+ <title>Group Management</title>
+</head>
+
+<body onload="prettyPrint()" style="overflow: auto;">
+
+<div id="toc-navigation">
+ <div id="profile">
+ <p><img alt="Mobile native" src="../../images/mobile_s_n.png"/></p>
+ </div>
+ <div id="toc_border"><div id="toc">
+ <p class="toc-title">Content</p>
+ <ul class="toc">
+ <li><a href="#retrieving">Retrieving Groups</a></li>
+ <li><a href="#updating">Updating Groups</a></li>
+ <li><a href="#creating">Creating a Group</a></li>
+ <li><a href="#deleting">Deleting a Group</a></li>
+ <li><a href="#managing">Managing Group Members</a></li>
+ </ul>
+ <p class="toc-title">Related Info</p>
+ <ul class="toc">
+ <li><a href="../../../../org.tizen.guides/html/native/personal/contacts_n.htm">Contacts Guide</a></li>
+ <li><a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__SOCIAL__CONTACTS__SVC__MODULE.html">Contacts API for Mobile Native</a></li>
+ </ul>
+ </div></div>
+</div>
+<div id="container"><div id="contents"><div class="content">
+<h1>Group Management</h1>
+
+<p>The basic tasks involved in group management operations are retrieving group information, creating, updating, and deleting groups, and managing group members. The following sections provide you with the fundamental building blocks for combining individual contacts to groups to manage them more efficiently.</p>
+
+<h2 id="retrieving">Retrieving Groups</h2>
+
+<p>A group is a collection of contacts from the same address book. Retrieving a single group is very similar to retrieving a single person: use the same function (<span style="font-family: Courier New,Courier,monospace">contacts_db_get_record()</span>) while setting the first parameter to the relevant group view (<span style="font-family: Courier New,Courier,monospace">_contacts_group._uri</span>).</p>
+
+<pre class="prettyprint">
+contacts_record_h group;
+int group_id = ... /* Get the group ID */
+int error_code;
+
+error_code = contacts_db_get_record(_contacts_group._uri, group_id, &group);
+
+if (error_code != CONTACTS_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "failed to get record: error code = %d", error_code);
+</pre>
+
+<p>The following example retrieves a list of groups, whose name contains the strings "neighbors" or "friend". You can search the groups meeting the condition using queries and filters:</p>
+
+<ol>
+<li>Create a filter handle.</li>
+<li>Add search conditions to the filter handle.
+<p>As shown in the example, the search strings and the <span style="font-family: Courier New,Courier,monospace">OR</span> operator are added to the filter handle.</p></li>
+<li>Make a query with the filter, and apply the query to the Contacts database.</li>
+</ol>
+
+<p>To simplify the example code, error handling has been omitted.</p>
+
+<pre class="prettyprint">
+contacts_list_h list = NULL;
+contacts_query_h query = NULL;
+contacts_filter_h filter = NULL;
+int error_code;
+
+error_code = contacts_query_create(_contacts_group._uri, &query);
+error_code = contacts_filter_create(_contacts_group._uri, &filter);
+
+error_code = contacts_filter_add_str(filter, _contacts_group.name, CONTACTS_MATCH_CONTAINS, "neighbors");
+error_code = contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_OR);
+error_code = contacts_filter_add_str(filter, _contacts_group.name, CONTACTS_MATCH_CONTAINS, "friend");
+
+error_code = contacts_query_set_filter(query, filter);
+error_code = contacts_db_get_records_with_query(query, 0, 0, &list);
+
+/* Destroy the filter and query handles and release all their resources */
+error_code = contacts_filter_destroy(filter);
+error_code = contacts_query_destroy(query);
+</pre>
+
+<p>The third parameter of the <span style="font-family: Courier New,Courier,monospace">contacts_db_get_records_with_query()</span> function defines a limit for the number of results. Since the parameter is set to <span style="font-family: Courier New,Courier,monospace">0</span> in the above example, the function returns all the groups matching the query.</p>
+
+<h2 id="updating">Updating Groups</h2>
+
+<p>To update information in an existing group, you must first retrieve the group to update. Then, you can change the group properties, apply the changes to the database, and finally destroy the group handle and release all the resources for it.</p>
+
+<ol>
+<li>Retrieve the group you want to update:
+<pre class="prettyprint">
+int group_id = ... /* Get the group ID */
+
+contacts_record_h group = NULL;
+
+error_code = contacts_db_get_record(_contacts_group._uri, group_id, &group);
+</pre>
+
+<p>You can also retrieve the group using a search function with queries, such as <span style="font-family: Courier New,Courier,monospace">contacts_db_get_records_with_query()</span>.</p>
+</li>
+<li>Set the properties to be changed.
+<p>The following example changes the name and image of the group:</p>
+
+<pre class="prettyprint">
+error_code = contacts_record_set_str(group, _contacts_group.name, "Family");
+
+char *resource_path = app_get_resource_path();
+char temp_path[1024];
+snprintf(temp_path, sizeof(temp_path), "%s/group_image_new.jpg", resource_path);
+free(resource_path);
+error_code = contacts_record_set_str(group, _contacts_group.image_path, temp_path);
+</pre>
+</li>
+<li>Apply the changes to the database:
+<pre class="prettyprint">
+error_code = contacts_db_update_record(group);
+</pre>
+</li>
+<li>Destroy the handle and release its resources.
+<p>If you set the second parameter to <span style="font-family: Courier New,Courier,monospace">true</span>, the function destroys any child records automatically.</p>
+
+<pre class="prettyprint">
+error_code = contacts_record_destroy(group, true);
+</pre>
+</li>
+</ol>
+
+<h2 id="creating">Creating a Group</h2>
+<p>To create a new group, you must create a group handle, set the group properties, insert the group into the database, and destroy the group handle:</p>
+<ol>
+<li>Create a group handle.
+<p>The first parameter of the <span style="font-family: Courier New,Courier,monospace">contacts_record_create()</span> function specifies the record type to be created. In this case, the value is the <span style="font-family: Courier New,Courier,monospace">_contacts_group._uri</span> property, because you are creating a group. The second parameter stores the new group handle.</p>
+<pre class="prettyprint">
+contacts_record_h group = NULL;
+
+error_code = contacts_record_create(_contacts_group._uri, &group);
+</pre>
+</li>
+<li>Set the group properties.
+<p>You can set the group properties using the <span style="font-family: Courier New,Courier,monospace">contacts_record_set_XXX()</span> functions with the relevant properties as the second parameter. Depending on the property type, you must use the proper functions, respectively.</p>
+<ul>
+<li>If you set the group name, which is a <span style="font-family: Courier New,Courier,monospace">string</span> type, use the <span style="font-family: Courier New,Courier,monospace">contacts_record_set_str()</span> function with the <span style="font-family: Courier New,Courier,monospace">_contacts_group.name</span> property as the second parameter:
+
+<pre class="prettyprint">
+error_code = contacts_record_set_str(group, _contacts_group.name, "Neighbors");
+</pre>
+</li>
+<li>If you set the group image property, first define the image file path and then set it to the property similarly as the group name above:
+<pre class="prettyprint">
+char *resource_path = app_get_resource_path();
+char temp_path[1024];
+snprintf(temp_path, sizeof(temp_path), "%s/group_image.jpg", resource_path);
+free(resource_path);
+error_code = contacts_record_set_str(group, _contacts_group.image_path, temp_path);
+</pre>
+</li></ul>
+<p>Set other group properties similarly, as needed.</p>
+</li>
+<li>Insert the group into the Contacts database:
+<pre class="prettyprint">
+int added_group_id = -1;
+
+error_code = contacts_db_insert_record(group, &added_group_id);
+</pre>
+</li>
+<li>Destroy the group handle and release its resources.
+<p>If you set the second parameter to <span style="font-family: Courier New,Courier,monospace">true</span>, the function destroys any child records automatically.</p>
+<pre class="prettyprint">
+error_code = contacts_record_destroy(group, true);
+</pre>
+</li>
+</ol>
+
+<h2 id="deleting">Deleting a Group</h2>
+<p>You can delete a group record from the Contacts database exactly like you delete a person: use the <span style="font-family: Courier New,Courier,monospace">contacts_db_delete_record()</span> function. The difference is the first parameter, which for the group deletion is set to the group property (<span style="font-family: Courier New,Courier,monospace">_contacts_group._uri</span>). The ID of the group to be deleted is given as the second parameter.</p>
+
+<pre class="prettyprint">
+int group_id = ... /* Get the group ID */
+
+error_code = contacts_db_delete_record(_contacts_group._uri, group_id);
+</pre>
+
+<h2 id="managing">Managing Group Members</h2>
+<p>Group members are contacts from the same address book. With a contact ID and group ID on hand, you can add and remove contacts within a group using the <span style="font-family: Courier New,Courier,monospace">contacts_group_add_contact()</span> and <span style="font-family: Courier New,Courier,monospace">contacts_group_remove_contact()</span> functions:</p>
+<ul>
+<li>Adding a group member:
+<pre class="prettyprint">
+int contact_id = ... /* Get the contact ID */
+int group_id = ... /* Get the group ID */
+
+error_code = contacts_group_add_contact(group_id, contact_id);
+</pre>
+</li>
+<li>Removing a group member:
+<pre class="prettyprint">
+int contact_id = ... /* Get the contact ID */
+int group_id = ... /* Get the group ID */
+
+error_code = contacts_group_remove_contact(group_id, contact_id);
+</pre>
+</li>
+</ul>
+
+<p>Since each contact is associated with a person, you can retrieve all the member details of a group as follows:</p>
+<ol>
+<li>Create and run a query for retrieving a list of all persons in the group:
+<pre class="prettyprint">
+contacts_query_h query = NULL;
+contacts_filter_h filter = NULL;
+contacts_list_h list = NULL;
+
+/* Create a person query with a filter for the group ID */
+contacts_query_create(_contacts_person_group_assigned._uri, &query);
+contacts_filter_create(_contacts_person_group_assigned._uri, &filter);
+contacts_filter_add_int(filter, _contacts_person_group_assigned.group_id, CONTACTS_MATCH_EQUAL, group_id);
+contacts_query_set_filter(query, filter);
+
+/* Run the query to retrieve a list of all persons assigned to the specified group */
+contacts_db_get_records_with_query(query, 0, 0, &list);
+</pre>
+</li>
+<li>Iterate through the query answer list and retrieve the person details.
+<p>The following example retrieves the ID and display name of each person.</p>
+<pre class="prettyprint">
+contacts_record_h person = NULL;
+int error_code;
+
+while (contacts_list_get_current_record_p(list, &person) == CONTACTS_ERROR_NONE) {
+ int person_id;
+ contacts_record_get_int(person, _contacts_person_group_assigned.person_id, &person_id);
+ dlog_print(DLOG_DEBUG, LOG_TAG, "Person id: %d", person_id);
+
+ char *display_name;
+ contacts_record_get_str_p(person, _contacts_person_group_assigned.display_name, &display_name);
+ dlog_print(DLOG_DEBUG, LOG_TAG, "Display name: %s", display_name);
+
+ error_code = contacts_list_next(list);
+ if (error_code != CONTACTS_ERROR_NONE)
+ break;
+}
+</pre>
+</li>
+<li>When no longer needed, destroy the handles to release all the resources assigned to them:
+<pre class="prettyprint">
+contacts_list_destroy(list, true);
+contacts_filter_destroy(filter);
+contacts_query_destroy(query);
+</pre>
+</li>
+</ol>
+
+<script type="text/javascript" src="../../scripts/jquery.zclip.min.js"></script>
+<script type="text/javascript" src="../../scripts/showhide.js"></script>
+</div></div></div>
+
+<a class="top sms" href="#"><img src="../../images/btn_top.gif" alt="Go to top" /></a>
+
+<div id="footer">
+<p class="footer">Except as noted, this content - excluding the Code Examples - is licensed under <a href="http://creativecommons.org/licenses/by/3.0/legalcode" target="_blank">Creative Commons Attribution 3.0</a> and all of the Code Examples contained herein are licensed under <a href="https://www.tizen.org/bsd-3-clause-license" target="_blank">BSD-3-Clause</a>.<br/>For details, see the <a href="https://www.tizen.org/content-license" target="_blank">Content License</a>.</p>
+</div>
+
+<script type="text/javascript">
+var _gaq = _gaq || [];
+_gaq.push(['_setAccount', 'UA-25976949-1']);
+_gaq.push(['_trackPageview']);
+(function() {
+var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+})();
+</script>
+
+</body>
+</html>
+
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <meta http-equiv="X-UA-Compatible" content="IE=9" />
+ <link rel="stylesheet" type="text/css" href="../../css/styles.css" />
+ <link rel="stylesheet" type="text/css" href="../../css/snippet.css" />
+ <script type="text/javascript" src="../../scripts/snippet.js"></script>
+ <script type="text/javascript" src="../../scripts/jquery.util.js" charset="utf-8"></script>
+ <script type="text/javascript" src="../../scripts/common.js" charset="utf-8"></script>
+ <script type="text/javascript" src="../../scripts/core.js" charset="utf-8"></script>
+ <script type="text/javascript" src="../../scripts/search.js" charset="utf-8"></script>
+
+ <title>Contact Management</title>
+</head>
+
+<body onload="prettyPrint()" style="overflow: auto;">
+
+<div id="toc-navigation">
+ <div id="profile">
+ <p><img alt="Mobile native" src="../../images/mobile_s_n.png"/></p>
+ </div>
+ <div id="toc_border"><div id="toc">
+ <p class="toc-title">Content</p>
+ <ul class="toc">
+ <li><a href="#initializing">Connecting to the Contact Service</a></li>
+ <li><a href="#retrieving">Retrieving Persons</a></li>
+ <li><a href="#updating">Updating Contacts</a></li>
+ <li><a href="#creating">Creating a Contact</a></li>
+ <li><a href="#deleting">Deleting a Person</a></li>
+ <li><a href="#linking">Linking and Unlinking Persons and Contacts</a></li>
+ </ul>
+ <p class="toc-title">Related Info</p>
+ <ul class="toc">
+ <li><a href="../../../../org.tizen.guides/html/native/personal/contacts_n.htm">Contacts Guide</a></li>
+ <li><a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__SOCIAL__CONTACTS__SVC__MODULE.html">Contacts API for Mobile Native</a></li>
+ </ul>
+ </div></div>
+</div>
+<div id="container"><div id="contents"><div class="content">
+<h1>Contact Management</h1>
+
+<p>The basic tasks involved in contact management operations are creating and updating contacts, retrieving and deleting persons, and linking contacts and persons. The following sections provide you with the fundamental building blocks for managing contact details in the Contacts database.</p>
+
+<h2 id="initializing">Connecting to the Contact Service</h2>
+
+<p>To initialize the contact service and use the functions and data types of the Contacts API, you must include the <span style="font-family: Courier New,Courier,monospace"><contacts.h></span> header file in your application. To be able to access the Contacts database and operations, such as fetching, inserting, or updating, you must also connect to the contact service by calling the <span style="font-family: Courier New,Courier,monospace">contacts_connect()</span> function.</p>
+
+<pre class="prettyprint">
+#include <contacts.h>
+
+int error_code;
+error_code = contacts_connect();
+
+if (error_code != CONTACTS_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "failed to connect contacts: error code = %d", error_code);
+</pre>
+
+<p>When you no longer need it, disconnect from the contact service using the <span style="font-family: Courier New,Courier,monospace">contacts_disconnect()</span> function.</p>
+
+<table class="note">
+ <tbody>
+ <tr>
+ <th class="note">Note</th>
+ </tr>
+ <tr>
+ <td class="note">To use the Contacts API, your application has to request permission by adding the following privileges to the <span style="font-family: Courier New,Courier,monospace">tizen-manifest.xml</span> file in the application package:
+
+<pre class="prettyprint">
+<privileges>
+ <privilege>http://tizen.org/privilege/contact.read</privilege>
+ <privilege>http://tizen.org/privilege/contact.write</privilege>
+</privileges>
+</pre>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+
+<h2 id="retrieving">Retrieving Persons</h2>
+
+<p>You can retrieve person details in many ways:</p>
+
+<ul>
+<li>
+<p>If a person ID is known in your application, you can retrieve the person's details using the <span style="font-family: Courier New,Courier,monospace">contacts_db_get_record()</span> function, whose first parameter is the <span style="font-family: Courier New,Courier,monospace">_contacts_person._uri</span> view:</p>
+
+<pre class="prettyprint">
+contacts_record_h person = NULL;
+const int person_id = ... /* Get the person ID */
+int error_code;
+
+error_code = contacts_db_get_record(_contacts_person._uri, person_id, &person);
+
+if (error_code != CONTACTS_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "failed to get record: error code = %d", error_code);
+</pre>
+</li>
+<li>
+<p>If you need to retrieve a list of persons matching a search keyword without knowing a specific person ID, you can use the <span style="font-family: Courier New,Courier,monospace">contacts_db_search_records()</span> function. The third parameter is the offset, meaning the record index from which to search, and the fourth parameter sets a limit to the number of results, where 0 means that all the matched records are retrieved.</p>
+
+<p>The following example shows how to find all person records that contain the keyword "John".</p>
+
+<pre class="prettyprint">
+contacts_list_h list = NULL;
+
+error_code = contacts_db_search_records(_contacts_person._uri, "John", 0, 0, &list);
+
+if (error_code != CONTACTS_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "failed to search records: error code = %d", error_code);
+</pre>
+
+</li>
+<li>
+<p>If you have more complex search requirements, you can use queries and filters to retrieve records:</p>
+<ul><li>Queries are used to retrieve data that satisfies given criteria, for example, an <span style="font-family: Courier New,Courier,monospace">integer</span> property being greater than a given value, or a <span style="font-family: Courier New,Courier,monospace">string</span> property containing a given substring.</li>
+<li>Filters specify the search conditions for queries. When creating a filter, you must specify the filter type using the <span style="font-family: Courier New,Courier,monospace">_uri</span> property.
+<p>Conditions can be joined by using the logical operators <span style="font-family: Courier New,Courier,monospace">AND</span> and <span style="font-family: Courier New,Courier,monospace">OR</span>. For contact filters, there are enumerations of operators and conditions for each type: <a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__SOCIAL__CONTACTS__SVC__FILTER__MODULE.html#ga2111e378d844cc7659ed5b4ff96bc433">contacts_filter_operator_e</a>, <a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__SOCIAL__CONTACTS__SVC__FILTER__MODULE.html#gad0453305468fab6453b07183e31628ba">contacts_match_int_flag_e</a>, and <a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__SOCIAL__CONTACTS__SVC__FILTER__MODULE.html#ga5a4ee5c71ae14d0fbf7520597514f0c2">contacts_match_str_flag_e</a>.</p>
+</li>
+</ul>
+<p>The following code demonstrates how to retrieve the contacts associated with a person using queries and filters. As a person can be associated with 1 or more contacts, the number of the contact records for the person can be 1 or more.</p>
+<p>To simplify the example code, error handling has been omitted, except for the final check.</p>
+
+<pre class="prettyprint">
+static bool
+_get_associated_contacts(contacts_record_h record, contacts_list_h *associated_contacts)
+{
+ int error_code;
+ int person_id;
+ contacts_query_h query = NULL;
+ contacts_filter_h filter = NULL;
+
+ /* Retrieve the person ID from the person record */
+ error_code = contacts_record_get_int(record, _contacts_person.id, &person_id);
+
+ /* Create a contact query with a filter for the person ID */
+ error_code = CONTACTS_ERROR_NONE;
+ error_code += contacts_query_create(_contacts_contact._uri, &query);
+ error_code += contacts_filter_create(_contacts_contact._uri, &filter);
+ error_code += contacts_filter_add_int(filter, _contacts_contact.person_id, CONTACTS_MATCH_EQUAL, person_id);
+ error_code += contacts_query_set_filter(query, filter);
+
+ /* Run the query to retrieve a list of all contacts associated with the person ID */
+ error_code += contacts_db_get_records_with_query(query, 0, 0, associated_contacts);
+
+ /* Destroy the filter and query handles and release all their resources */
+ error_code += contacts_filter_destroy(filter);
+ error_code += contacts_query_destroy(query);
+
+ if (error_code != CONTACTS_ERROR_NONE)
+ return false;
+
+ return true;
+}
+</pre>
+
+<p>The following example uses queries and filters to retrieve a person's default phone number. If a person is associated with multiple phone numbers, one of them is defined as the default phone number. To determine the default phone number, you can check the <span style="font-family: Courier New,Courier,monospace">is_primary_default</span> property of the <span style="font-family: Courier New,Courier,monospace">_contacts_person_number</span> view. For the default phone number, the property is set to <span style="font-family: Courier New,Courier,monospace">true</span>.</p>
+
+<pre class="prettyprint">
+static bool
+_get_default_phone_number(contacts_record_h record, char **default_phone_number)
+{
+ contacts_query_h query = NULL;
+ contacts_filter_h filter = NULL;
+ contacts_list_h list = NULL;
+ contacts_record_h record_person_number = NULL;
+ int person_id;
+ int error_code = CONTACTS_ERROR_NONE;
+
+ /* Retrieve the person ID from the person record */
+ error_code += contacts_record_get_int(record, _contacts_person.id, &person_id);
+
+ /* Create a phone number query with filters for the person ID and default phone number */
+ error_code += contacts_query_create(_contacts_person_number._uri, &query);
+ error_code += contacts_filter_create(_contacts_person_number._uri, &filter);
+ error_code += contacts_filter_add_int(filter, _contacts_person_number.person_id, CONTACTS_MATCH_EQUAL, person_id);
+ error_code += contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_AND);
+ error_code += contacts_filter_add_bool(filter, _contacts_person_number.is_primary_default, true);
+ error_code += contacts_query_set_filter(query, filter);
+
+ /* Run the query to retrieve the phone number records containing the default phone number */
+ error_code += contacts_db_get_records_with_query(query, 0, 0, &list);
+
+ /* Retrieve the current record from the query list */
+ error_code += contacts_list_get_current_record_p(list, &record_person_number);
+
+ /* Retrieve the phone number from the phone number record */
+ error_code += contacts_record_get_str(record_person_number, _contacts_person_number.number, default_phone_number);
+
+ /* Destroy the list, filter, and query handles and release all their resources */
+ contacts_list_destroy(list, true);
+ contacts_filter_destroy(filter);
+ contacts_query_destroy(query);
+
+ if (error_code != CONTACTS_ERROR_NONE)
+ return false;
+
+ return true;
+}
+</pre>
+</li>
+</ul>
+
+
+<h2 id="updating">Updating Contacts</h2>
+
+<p>To update information of the existing contacts, you must retrieve, change, and save the information you want to update:</p>
+
+<ol>
+<li>Retrieve the contact you want to update using the <span style="font-family: Courier New,Courier,monospace">contacts_db_get_record()</span> function with the contact ID as the second parameter. Alternatively, you can also retrieve the contact using a search function, such as <span style="font-family: Courier New,Courier,monospace">contacts_db_get_records_with_query()</span>.
+<pre class="prettyprint">
+int contact_id = ... /* Get the contact ID */
+contacts_record_h contact = NULL;
+
+error_code = contacts_db_get_record(_contacts_contact._uri, contact_id, &contact);
+</pre>
+</li>
+<li>Set the properties you want to update:
+<ul><li>The following example sets a new first name for the contact record by updating a child record:
+<pre class="prettyprint">
+contacts_record_h name = NULL;
+/* Retrieve the contact's name record */
+/* Record index is set to 0, since there is only 1 child record of type "name" */
+error_code = contacts_record_get_child_record_at_p(contact, _contacts_contact.name, 0, &name);
+/* Change the first name in the name record */
+error_code = contacts_record_set_str(name, _contacts_name.first, "Mark");
+</pre>
+</li>
+<li>The following example set a new birthday event for the contact by updating another child record.
+<p>The example assumes that the birthday is the only event for the contact, meaning that the event record can be retrieved using the <span style="font-family: Courier New,Courier,monospace">contacts_record_get_child_record_at_p()</span> function with index 0 as the second parameter. If the contact has multiple events, you must iterate through them.</p>
+<pre class="prettyprint">
+contacts_record_h event = NULL;
+/* Retrieve the contact's birthday event record */
+error_code = contacts_record_get_child_record_at_p(contact, _contacts_contact.event, 0, &event);
+/* Change the date in the event record */
+int new_date = 1990 * 10000 + 6 * 100 + 21;
+error_code = contacts_record_set_int(event, _contacts_event.date, new_date);
+</pre>
+</li>
+<li>The following example shows the iteration to change the country in all contact addresses, which are child records of the contact. Each address can be traversed by using the <span style="font-family: Courier New,Courier,monospace">contacts_record_get_child_record_at_p()</span> function.
+
+<pre class="prettyprint">
+int contact_id = ... /* Get the contact ID */
+int address_num = 0;
+int i = 0;
+
+contacts_db_get_record(_contacts_contact._uri, contact_id, &contact);
+contacts_record_get_child_record_count(count, _contacts_contact.address, &address_num);
+
+for (i = 0; i < address_num; i++) {
+ contacts_record_h address = NULL;
+ contacts_record_get_child_record_at_p(contact, _contacts_contact.address, i, &address);
+ contacts_record_set_str(address, _contacts_address.country, "Korea");
+}
+</pre>
+</li>
+</ul>
+</li>
+<li>Apply the changes to the database using the <span style="font-family: Courier New,Courier,monospace">contacts_db_update_record()</span> function:
+
+<pre class="prettyprint">
+error_code = contacts_db_update_record(contact);
+
+if (error_code != CONTACTS_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "failed to update record: error code = %d", error_code);
+</pre>
+
+<table class="note">
+ <tbody>
+ <tr>
+ <th class="note">Note</th>
+ </tr>
+ <tr>
+ <td class="note">The <span style="font-family: Courier New,Courier,monospace">contacts_record_set_XXX()</span> functions only change the data in the memory object, not in the Contacts database. Normally, to update the database, you must update each record separately using the <span style="font-family: Courier New,Courier,monospace">contacts_db_update_record()</span> function. However, if you retrieve a child record using the <span style="font-family: Courier New,Courier,monospace">contacts_record_get_child_record_at_p()</span> function, you only need to update the parent record to the database; the child record is updated automatically with the parent record.</td>
+ </tr>
+ </tbody>
+ </table>
+</li>
+<li>When no longer needed, destroy the contact handle and release all its resources using the <span style="font-family: Courier New,Courier,monospace">contacts_record_destroy()</span> function.
+<p>If you set the second parameter to <span style="font-family: Courier New,Courier,monospace">true</span>, the function destroys any child records automatically, irrespective of how the child records were added (individually or along with their parent record).</p>
+
+<pre class="prettyprint">
+error_code = contacts_record_destroy(contact, true);
+
+if (error_code != CONTACTS_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "failed to destroy record: error code = %d", error_code);
+</pre>
+</li>
+</ol>
+<h2 id="creating">Creating a Contact</h2>
+
+<p>To create a new contact, you must create a contact handle, set the contact properties, insert the contact into the database, and destroy the handle:</p>
+
+<ol>
+<li>Create a contact handle using the <span style="font-family: Courier New,Courier,monospace">contacts_record_create()</span> function with the <span style="font-family: Courier New,Courier,monospace">_contacts_contact._uri</span> property as the first parameter:
+
+<pre class="prettyprint">
+contacts_record_h contact;
+
+error_code = contacts_record_create(_contacts_contact._uri, &contact);
+
+if (error_code != CONTACTS_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "failed to create record: error code = %d", error_code);
+</pre>
+
+<p>Remember that records created with the <span style="font-family: Courier New,Courier,monospace">contacts_record_create()</span> function are memory objects, with <span style="font-family: Courier New,Courier,monospace">contacts_record_h</span> type variables as their handles. If you change these objects, the changes are not reflected in the Contacts database until you explicitly insert or update the objects to the database using the <span style="font-family: Courier New,Courier,monospace">contacts_db_insert_record()</span> or <span style="font-family: Courier New,Courier,monospace">contacts_db_update_record()</span> function.</p></li>
+<li>Set the contact properties.
+<p>The following examples set the contact name, image, phone number, and event.</p>
+<p>To simplify the example code, error handling has been omitted.</p>
+<ul>
+<li>Name
+<p>Create a name record, set the string values, "John" and "Smith", to the name, and set the name record as a child record of the contact record.</p>
+
+<p>When creating the name record, the first parameter of the <span style="font-family: Courier New,Courier,monospace">contacts_record_create()</span> function is the <span style="font-family: Courier New,Courier,monospace">_contacts_name._uri</span> property.</p>
+<pre class="prettyprint">
+contacts_record_h name;
+
+error_code = contacts_record_create(_contacts_name._uri, &name);
+
+error_code = contacts_record_set_str(name, _contacts_name.first, "John");
+error_code = contacts_record_set_str(name, _contacts_name.last, "Smith");
+
+error_code = contacts_record_add_child_record(contact, _contacts_contact.name, name);
+</pre>
+</li>
+<li>Image
+<p>Similarly, create an image record, set the values of the property, and add the image record to the contact as a child record:</p>
+<ul><li>Create the image record with the <span style="font-family: Courier New,Courier,monospace">_contacts_image._uri</span> property.</li>
+<li>Set the path for the image in the <span style="font-family: Courier New,Courier,monospace">caller_id_path[]</span> variable, which is saved in the <span style="font-family: Courier New,Courier,monospace">_contacts_image.path</span> property by the <span style="font-family: Courier New,Courier,monospace">contacts_record_set_str()</span> function.</li>
+</ul>
+
+<pre class="prettyprint">
+contacts_record_h image;
+
+error_code = contacts_record_create(_contacts_image._uri, &image);
+
+char *resource_path = app_get_resource_path();
+char caller_id_path[1024];
+
+snprintf(caller_id_path, sizeof(caller_id_path), "%s/caller_id.jpg", resource_path);
+free(resource_path);
+
+error_code = contacts_record_set_str(image, _contacts_image.path, caller_id_path);
+
+error_code = contacts_record_add_child_record(contact, _contacts_contact.image, image);
+</pre>
+</li>
+<li>Phone number
+<p>Similarly again, create a phone number record, set the number, and add the phone number record to the contact as a child record.</p>
+<p>When creating a phone number record, use the <span style="font-family: Courier New,Courier,monospace">_contacts_number._uri</span> property as the second parameter of the <span style="font-family: Courier New,Courier,monospace">contacts_record_create()</span> function.</p>
+
+<pre class="prettyprint">
+contacts_record_h number;
+
+error_code = contacts_record_create(_contacts_number._uri, &number);
+
+error_code = contacts_record_set_str(number, _contacts_number.number, "+8210-1234-5678");
+
+error_code = contacts_record_add_child_record(contact, _contacts_contact.number, number);
+</pre>
+</li>
+<li>Event
+<p>An event consists of a type, date, and other properties. You can set various types of events, as defined in the <a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__SOCIAL__CONTACTS__SVC__RECORD__MODULE.html#ga434cc4b7cec62ccab70fa4825ce0801d">contacts_event_type_e</a> enumeration. If the event type is <span style="font-family: Courier New,Courier,monospace">CUSTOM</span>, you can set a custom label for the event using the <span style="font-family: Courier New,Courier,monospace">_contacts_event.label</span> property.</p>
+
+<p>The following example sets a birthday event:</p>
+<ul>
+<li>In creating an event record, use the <span style="font-family: Courier New,Courier,monospace">_contacts_event._uri</span> property.</li>
+<li>The event type is set as <span style="font-family: Courier New,Courier,monospace">CONTACTS_EVENT_TYPE_BIRTH</span> in the <span style="font-family: Courier New,Courier,monospace">_contacts_event.type</span> property.</li>
+<li>When you set the event date, the date is an <span style="font-family: Courier New,Courier,monospace">integer</span> type property (<span style="font-family: Courier New,Courier,monospace">_contact_event.date</span>), calculated as year * 10000 + month * 100 + day.</li>
+</ul>
+<p>Add the event record to the contact as a child record using the <span style="font-family: Courier New,Courier,monospace">contacts_record_add_child_record()</span> function.</p>
+<pre class="prettyprint">
+contacts_record_h event;
+
+error_code = contacts_record_create(_contacts_event._uri, &event);
+
+error_code = contacts_record_set_int(event, _contacts_event.type, CONTACTS_EVENT_TYPE_BIRTH);
+
+int year = 1990;
+int month = 5;
+int day = 21;
+int int_date = year * 10000 + month * 100 + day;
+
+error_code = contacts_record_set_int(event, _contacts_event.date, int_date);
+
+error_code = contacts_record_add_child_record(contact, _contacts_contact.event, event);
+</pre>
+</li>
+</ul>
+<p>For other contact properties, you can follow the same steps: create an appropriate record, set the values in the properties, and add the record to the contact as a child record.</p>
+</li>
+<li>Insert the contact into the Contacts database using the <span style="font-family: Courier New,Courier,monospace">contacts_db_insert_record()</span> function. All the child records added to the contact are inserted automatically along with the parent. The second parameter of the function is for the contact ID, which is unique and assigned by the system.
+
+<pre class="prettyprint">
+int id = -1;
+
+error_code = contacts_db_insert_record(contact, &id);
+</pre>
+</li>
+<li>Destroy the contact handle and release all its resources using the <span style="font-family: Courier New,Courier,monospace">contacts_record_destroy()</span> function.
+<p>If you set the second parameter to <span style="font-family: Courier New,Courier,monospace">true</span>, the function destroys any child records automatically, irrespective of how the child records were added (individually or along with their parent record).</p>
+
+<pre class="prettyprint">
+error_code = contacts_record_destroy(contact, true);
+</pre>
+</li>
+</ol>
+<h2 id="deleting">Deleting a Person</h2>
+
+<p>By using the <span style="font-family: Courier New,Courier,monospace">contacts_db_delete_record()</span> function, you can delete a person record from the database with related child records. The person ID is given to the function as the second parameter.</p>
+
+<pre class="prettyprint">
+int person_id = ... /* Get the person ID */
+
+error_code = contacts_db_delete_record(_contacts_person._uri, person_id);
+</pre>
+
+<h2 id="linking">Linking and Unlinking Persons and Contacts</h2>
+
+<p>A person can be associated with multiple contacts, so you need to know how to manage the associations between a person and its contacts: linking and unlinking.</p>
+
+<p>When you create a contact, it is automatically linked to a person:</p>
+<ul>
+<li>You can link the new contact to an existing person by setting the <span style="font-family: Courier New,Courier,monospace">_contacts_contact.link_mode</span> property as <span style="font-family: Courier New,Courier,monospace">CONTACTS_CONTACT_LINK_MODE_NONE</span>.
+<p>Linking is determined based on the contact properties for phone numbers and email addresses (<span style="font-family: Courier New,Courier,monospace">_contacts_number.number</span> and <span style="font-family: Courier New,Courier,monospace">_contacts_email.email</span>). If an existing person has the same phone number or email address, but in a different address book, the contact is automatically linked to that person. However, if the phone number or email address leads to an existing contact in the same address book, the linking does not work.</p></li>
+<li>If the contact cannot be linked to any existing person, a new person is automatically created and linked to the contact.</li>
+</ul>
+
+<pre class="prettyprint">
+contacts_record_h contact = NULL;
+
+error_code = CONTACTS_ERROR_NONE;
+error_code += contacts_record_create(_contacts_contact._uri, &contact);
+error_code += contacts_record_set_int(contact, _contacts_contact.link_mode, CONTACTS_CONTACT_LINK_MODE_NONE);
+
+contacts_record_h name = NULL;
+error_code += contacts_record_create(_contacts_name._uri, &name);
+error_code += contacts_record_set_str(name, _contacts_name.first, "John");
+error_code += contacts_record_add_child_record(contact, _contacts_contact.name, name);
+
+contacts_record_h number = NULL;
+error_code += contacts_record_create(_contacts_number._uri, &number);
+error_code += contacts_record_set_str(number, _contacts_number.number, "+8210-1234-5678");
+error_code += contacts_record_add_child_record(contact, _contacts_contact.number, number);
+
+/* Contact is linked automatically if an existing person has the same number in a different address book */
+error_code += contacts_db_insert_record(contact, NULL);
+
+contacts_record_destroy(contact, true);
+</pre>
+
+<p>You can modify the contact and person linking, as needed:</p>
+
+<ul>
+<li>To merge existing contacts into 1 person, use the <span style="font-family: Courier New,Courier,monospace">contacts_person_link_person()</span> function to link the contacts of one person to another person. The first parameter of the function is the ID of the person to be merged, and the second parameter is the ID of the person who will have all the merged contacts. After the linking, the former is deleted from the Contacts database. The latter person is left with both their original contacts and the other person's contacts.
+
+<pre class="prettyprint">
+int person_id1 = ... /* Get the person ID whose contacts are merged elsewhere */
+int person_id2 = ... /* Get the person ID to which contacts are merged */
+
+error_code = contacts_person_link_person(person_id1, person_id2);
+</pre>
+<p>The following figure illustrates the process of linking a person. Even though the contacts have different address books, they can be linked to the same person. After linking, the person2 record is destroyed automatically.</p>
+
+<p class="figure">Figure: Linking a person</p>
+<p align="center"><img alt="Linking a person" src="../../images/app_contacts_linking.png" /></p>
+</li>
+<li>To separate (unlink) a contact record from the person record, use the <span style="font-family: Courier New,Courier,monospace">contacts_person_unlink_contact()</span> function. The function removes the contact from the person, creates a new person, and links the contact to the new person.
+
+<pre class="prettyprint">
+int person_id = ... /* Get the person ID */
+int contact_id = ... /* Get the contact ID */
+int unlinked_person_id;
+
+error_code = contacts_person_unlink_contact(person_id, contact_id, &unlinked_person_id);
+</pre>
+
+<p>The following figure illustrates the process of unlinking a contact. After unlinking, the person3 record is newly created.</p>
+
+<p class="figure">Figure: Unlinking a contact</p>
+<p align="center"><img alt="Unlinking a contact" src="../../images/app_contacts_unlinking.png" /></p>
+</li>
+</ul>
+
+<script type="text/javascript" src="../../scripts/jquery.zclip.min.js"></script>
+<script type="text/javascript" src="../../scripts/showhide.js"></script>
+</div></div></div>
+
+<a class="top sms" href="#"><img src="../../images/btn_top.gif" alt="Go to top" /></a>
+
+<div id="footer">
+<p class="footer">Except as noted, this content - excluding the Code Examples - is licensed under <a href="http://creativecommons.org/licenses/by/3.0/legalcode" target="_blank">Creative Commons Attribution 3.0</a> and all of the Code Examples contained herein are licensed under <a href="https://www.tizen.org/bsd-3-clause-license" target="_blank">BSD-3-Clause</a>.<br/>For details, see the <a href="https://www.tizen.org/content-license" target="_blank">Content License</a>.</p>
+</div>
+
+<script type="text/javascript">
+var _gaq = _gaq || [];
+_gaq.push(['_setAccount', 'UA-25976949-1']);
+_gaq.push(['_trackPageview']);
+(function() {
+var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+})();
+</script>
+
+</body>
+</html>
+
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <meta http-equiv="X-UA-Compatible" content="IE=9" />
+ <link rel="stylesheet" type="text/css" href="../../css/styles.css" />
+ <link rel="stylesheet" type="text/css" href="../../css/snippet.css" />
+ <script type="text/javascript" src="../../scripts/snippet.js"></script>
+ <script type="text/javascript" src="../../scripts/jquery.util.js" charset="utf-8"></script>
+ <script type="text/javascript" src="../../scripts/common.js" charset="utf-8"></script>
+ <script type="text/javascript" src="../../scripts/core.js" charset="utf-8"></script>
+ <script type="text/javascript" src="../../scripts/search.js" charset="utf-8"></script>
+
+ <title>Creating Applications with Contacts</title>
+</head>
+
+<body onload="prettyPrint()" style="overflow: auto;">
+
+<div id="toc-navigation">
+ <div id="profile">
+ <p><img alt="Mobile native" src="../../images/mobile_s_n.png"/></p>
+ </div>
+ <div id="toc_border"><div id="toc">
+ <p class="toc-title">Related Info</p>
+ <ul class="toc">
+ <li><a href="../../../../org.tizen.guides/html/native/personal/contacts_n.htm">Contacts Guide</a></li>
+ <li><a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__SOCIAL__CONTACTS__SVC__MODULE.html">Contacts API for Mobile Native</a></li>
+ </ul>
+ </div></div>
+</div>
+<div id="container"><div id="contents"><div class="content">
+<h1>Creating Applications with Contacts</h1>
+
+<p>If you want to create applications that offer contact management features to the user, Tizen provides various options for you.</p>
+
+<p>You can handle people information in Tizen applications through various entities, such as contacts, groups, accounts, and address books. Optimal use of the contact features allows your application to take advantage of the data stored in the Contacts database on the device to provide a seamless user experience for the user.</p>
+
+<p>When creating a contact application, you can implement the following features:</p>
+
+<ul>
+<li><a href="app_contacts_basic_n.htm">Basic concepts</a>
+<ul>
+<li>To use contacts in the application, you must understand how the Contacts database is structured and contacts aggregated into persons.</li>
+<li>To use contact details in the application, you must understand how the information is organized in records and views, and how you can access and modify it.</li>
+</ul>
+</li>
+<li><a href="app_contacts_management_n.htm">Contact management</a>
+<ul>
+<li>You can manage contacts by creating and updating them.</li>
+<li>You can retrieve person information from the database with various filtered queries, and delete persons and their related contacts, when no longer needed.</li>
+<li>You can manage the linking between contacts and persons to ensure that each person has all related contacts attached to it.</li>
+</ul>
+</li>
+<li><a href="app_contacts_group_n.htm">Group management</a>
+<ul>
+<li>You can ease the contact management tasks by grouping related contacts to various groups.</li>
+<li>You can create, update, and delete groups.</li>
+<li>You can retrieve group information from the database with various filtered queries.</li>
+<li>You can manage group members by adding and removing contacts within a group.</li>
+</ul>
+</li>
+</ul>
+
+<script type="text/javascript" src="../../scripts/jquery.zclip.min.js"></script>
+<script type="text/javascript" src="../../scripts/showhide.js"></script>
+</div></div></div>
+
+<a class="top sms" href="#"><img src="../../images/btn_top.gif" alt="Go to top" /></a>
+
+<div id="footer">
+<p class="footer">Except as noted, this content - excluding the Code Examples - is licensed under <a href="http://creativecommons.org/licenses/by/3.0/legalcode" target="_blank">Creative Commons Attribution 3.0</a> and all of the Code Examples contained herein are licensed under <a href="https://www.tizen.org/bsd-3-clause-license" target="_blank">BSD-3-Clause</a>.<br/>For details, see the <a href="https://www.tizen.org/content-license" target="_blank">Content License</a>.</p>
+</div>
+
+<script type="text/javascript">
+var _gaq = _gaq || [];
+_gaq.push(['_setAccount', 'UA-25976949-1']);
+_gaq.push(['_trackPageview']);
+(function() {
+var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+})();
+</script>
+
+</body>
+</html>
+
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <meta http-equiv="X-UA-Compatible" content="IE=9" />
+ <link rel="stylesheet" type="text/css" href="../../css/styles.css" />
+ <link rel="stylesheet" type="text/css" href="../../css/snippet.css" />
+ <script type="text/javascript" src="../../scripts/snippet.js"></script>
+ <script type="text/javascript" src="../../scripts/jquery.util.js" charset="utf-8"></script>
+ <script type="text/javascript" src="../../scripts/common.js" charset="utf-8"></script>
+ <script type="text/javascript" src="../../scripts/core.js" charset="utf-8"></script>
+ <script type="text/javascript" src="../../scripts/search.js" charset="utf-8"></script>
+
+ <title>Creating Applications with Content Sharing</title>
+</head>
+
+<body onload="prettyPrint()" style="overflow: auto;">
+
+<div id="toc-navigation">
+ <div id="profile">
+ <p><img alt="Mobile native" src="../../images/mobile_s_n.png"/> <img alt="Wearable native" src="../../images/wearable_s_n.png"/></p>
+ </div>
+ <div id="toc_border"><div id="toc">
+ <p class="toc-title">Related Info</p>
+ <ul class="toc">
+ <li><a href="../../../../org.tizen.guides/html/native/app_management/app_controls_n.htm">Application Controls Guides</a></li>
+ <li><a href="../../../../org.tizen.guides/html/native/connectivity/nfc_n.htm">Near Field Communication (NFC) Guides</a></li>
+ <li><a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__APP__CONTROL__MODULE.html">App Control API for Mobile Native</a></li>
+ <li><a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__NETWORK__NFC__MODULE.html">NFC API for Mobile Native</a></li>
+ <li><a href="../../../../org.tizen.native.wearable.apireference/group__CAPI__APP__CONTROL__MODULE.html">App Control API for Wearable Native</a></li>
+ <li><a href="../../../../org.tizen.native.wearable.apireference/group__CAPI__NETWORK__NFC__MODULE.html">NFC API for Wearable Native</a></li>
+ </ul>
+ </div></div>
+</div>
+<div id="container"><div id="contents"><div class="content">
+<h1>Creating Applications with Content Sharing</h1>
+
+<p>If you want to create applications that offer content sharing features to the user, Tizen provides various options for you.</p>
+
+<p>You can share various types of content (text, binaries, and files) between applications on the same device using the application control features, which allow you to use features in other applications, or advertise your own features and allow others to use them. In addition, you can exchange simple NDEF messages (such as business cards) wirelessly with closely coupled devices using a Near Field Communication (NFC) P2P connection.</p>
+
+<p>When creating a content sharing application, you can implement the following features:</p>
+
+<ul>
+<li><a href="app_contentshare_send_n.htm">Sending content to other applications</a>
+
+<ul><li>You can send text to other applications. For example, a browser application can share the URL of a recently visited site with a messenger or email application.</li>
+<li>You can share single or multiple binary items with other applications.</li>
+<li>You can share files with other applications. For example, you can send an image file to a viewer application to allow the user to see it.</li>
+</ul>
+</li>
+<li><a href="app_contentshare_receive_n.htm">Receiving content from other applications</a>
+<ul>
+<li>To allow other applications to find and use your application features (such as share various data with you), you must advertise your available features by exporting them as application controls.</li>
+<li>When another application sends content to you, your application is automatically launched, and you must handle the incoming data using the application control callback.</li>
+<li>If the incoming request contains extra data, you must read it and react to it appropriately.</li>
+</ul>
+</li>
+<li><a href="app_contentshare_nfc_n.htm">Sharing through NFC</a>
+<ul>
+<li>To share data with other devices, you must first ensure that the device supports NFC and then initialize the NFC feature.</li>
+<li>You can send and receive simple NDEF messages through the NFC P2P connection.</li>
+</ul>
+</li>
+</ul>
+
+<p>To share content through application controls, you must use the App Control API (in <a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__APP__CONTROL__MODULE.html">mobile</a> and <a href="../../../../org.tizen.native.wearable.apireference/group__CAPI__APP__CONTROL__MODULE.html">wearable</a> applications). Application controls are a way of sharing an application's functionality in Tizen. The App Control API provides functions for launching other applications with a specific operation, URI, MIME type, and extra data, and for settings and getting the details:</p>
+<ul>
+<li>The mandatory operation information defines the action to be performed.</li>
+<li>The URI and MIME type contain information about the content to be handled.</li>
+<li>The extra data consists of key-value pairs, which provide additional information for the operation.</li>
+</ul>
+<p>By specifying a proper operation with the content information, your application can share the content with other applications. On the other hand, to allow other applications to find and launch your application, you can advertise your application features by declaring your application control information in the <span style="font-family: Courier New,Courier,monospace">tizen-manifest.xml</span> file.</p>
+
+
+<script type="text/javascript" src="../../scripts/jquery.zclip.min.js"></script>
+<script type="text/javascript" src="../../scripts/showhide.js"></script>
+</div></div></div>
+
+<a class="top sms" href="#"><img src="../../images/btn_top.gif" alt="Go to top" /></a>
+
+<div id="footer">
+<p class="footer">Except as noted, this content - excluding the Code Examples - is licensed under <a href="http://creativecommons.org/licenses/by/3.0/legalcode" target="_blank">Creative Commons Attribution 3.0</a> and all of the Code Examples contained herein are licensed under <a href="https://www.tizen.org/bsd-3-clause-license" target="_blank">BSD-3-Clause</a>.<br/>For details, see the <a href="https://www.tizen.org/content-license" target="_blank">Content License</a>.</p>
+</div>
+
+<script type="text/javascript">
+var _gaq = _gaq || [];
+_gaq.push(['_setAccount', 'UA-25976949-1']);
+_gaq.push(['_trackPageview']);
+(function() {
+var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+})();
+</script>
+
+</body>
+</html>
+
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <meta http-equiv="X-UA-Compatible" content="IE=9" />
+ <link rel="stylesheet" type="text/css" href="../../css/styles.css" />
+ <link rel="stylesheet" type="text/css" href="../../css/snippet.css" />
+ <script type="text/javascript" src="../../scripts/snippet.js"></script>
+ <script type="text/javascript" src="../../scripts/jquery.util.js" charset="utf-8"></script>
+ <script type="text/javascript" src="../../scripts/common.js" charset="utf-8"></script>
+ <script type="text/javascript" src="../../scripts/core.js" charset="utf-8"></script>
+ <script type="text/javascript" src="../../scripts/search.js" charset="utf-8"></script>
+
+ <title>Sharing through NFC</title>
+</head>
+
+<body onload="prettyPrint()" style="overflow: auto;">
+
+<div id="toc-navigation">
+ <div id="profile">
+ <p><img alt="Mobile native" src="../../images/mobile_s_n.png"/> <img alt="Wearable native" src="../../images/wearable_s_n.png"/></p>
+ </div>
+ <div id="toc_border"><div id="toc">
+ <p class="toc-title">Content</p>
+ <ul class="toc">
+ <li><a href="#initialize">Initializing NFC</a></li>
+ <li><a href="#message">Sending and Receiving Messages through NFC P2P</a></li>
+ </ul>
+ <p class="toc-title">Related Info</p>
+ <ul class="toc">
+ <li><a href="../../../../org.tizen.guides/html/native/connectivity/nfc_n.htm">Near Field Communication (NFC) Guides</a></li>
+ <li><a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__NETWORK__NFC__MODULE.html">NFC API for Mobile Native</a></li>
+ <li><a href="../../../../org.tizen.native.wearable.apireference/group__CAPI__NETWORK__NFC__MODULE.html">NFC API for Wearable Native</a></li>
+ </ul>
+ </div></div>
+</div>
+<div id="container"><div id="contents"><div class="content">
+<h1>Sharing through NFC</h1>
+
+<p>The basic tasks involved in sharing content through Near Field Communication (NFC) are to ensure that the device supports NFC, initialize the NFC feature, and exchange NDEF messages through the NFC P2P connection. The following sections provide you with the fundamental building blocks for sharing data with other devices.</p>
+
+<h2 id="initialize">Initializing NFC</h2>
+
+<p>NFC is an international standard (ISO/IEC 18092) that specifies an interface and a protocol for simple wireless interconnection of closely coupled devices.</p>
+
+<p>To initialize NFC:</p>
+
+<ol>
+<li>To use the functions and data types of the NFC API (in <a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__NETWORK__NFC__MODULE.html">mobile</a> and <a href="../../../../org.tizen.native.wearable.apireference/group__CAPI__NETWORK__NFC__MODULE.html">wearable</a> applications), include the <span style="font-family: Courier New,Courier,monospace"><nfc.h></span> header file in your application:
+
+<pre class="prettyprint">
+#include <nfc.h>
+</pre>
+</li>
+
+<li>Add the <span style="font-family: Courier New,Courier,monospace">http://tizen.org/privilege/nfc</span> privilege to the application manifest file.</li>
+
+<li>Check whether the device supports NFC by calling the <span style="font-family: Courier New,Courier,monospace">nfc_manager_is_supported()</span> function. It takes no parameters and returns <span style="font-family: Courier New,Courier,monospace">true</span> if NFC is supported on the device.
+
+<pre class="prettyprint">
+void
+Network_NFC_startup(void)
+{
+ gmainloop = g_main_loop_new(NULL, FALSE);
+ bool is_nfc_supported = nfc_manager_is_supported();
+ if (!is_nfc_supported)
+ dlog_print(DLOG_INFO, LOG_TAG, "is_nfc_supported NOT SUPPORTED");
+}
+</pre>
+<p>The <span style="font-family: Courier New,Courier,monospace">gmainloop</span> created above is used to wait for the results of calling asynchronous functions.</p>
+</li>
+<li>Call the <span style="font-family: Courier New,Courier,monospace">nfc_manager_initialize()</span> function to start the initialization:
+
+<pre class="prettyprint">
+int error_code = NFC_ERROR_NONE;
+
+error_code = nfc_manager_initialize();
+if (error_code != NFC_ERROR_NONE)
+ /* Error handling */
+
+g_timeout_add(1000, timeout_func, gmainloop);
+g_main_loop_run(gmainloop);
+</pre>
+
+<p>Run <span style="font-family: Courier New,Courier,monospace">gmainloop</span> to wait for the initialization result. It is closed when the time set in the <span style="font-family: Courier New,Courier,monospace">g_timeout_add()</span> function elapses. The time is defined in milliseconds, so in the above example the <span style="font-family: Courier New,Courier,monospace">timeout_func</span> is called after 1 second.</p>
+</li></ol>
+
+<h2 id="message">Sending and Receiving Messages through NFC P2P</h2>
+
+<p>The NFC Data Exchange Format (NDEF) is a packet message format used in the reader/writer and peer-to-peer (P2P) modes. In the following example, the NDEF message contains a business card of the device owner (name, phone number, and email address).</p>
+
+<p>To exchange a simple NDEF message through NFC P2P connection:</p>
+
+<ol>
+<li>Prepare the NDEF message:
+<ol type="a">
+<li><p>To create an NDEF message consisting of text records, use the <span style="font-family: Courier New,Courier,monospace">nfc_ndef_record_create_text()</span> function. The following example creates 3 records for a name, phone number, and email address:</p>
+
+<pre class="prettyprint">
+nfc_ndef_record_h ndef_name_record = NULL;
+nfc_ndef_record_h ndef_phone_record = NULL;
+nfc_ndef_record_h ndef_email_record = NULL;
+
+const char *name = "John Doe";
+const char *phone = "+82556666888";
+const char *email = "john.doe@tizen.org";
+
+nfc_ndef_record_create_text(&ndef_name_record, name, "en-US", NFC_ENCODE_UTF_8);
+nfc_ndef_record_create_text(&ndef_phone_record, phone, "en-US", NFC_ENCODE_UTF_8);
+nfc_ndef_record_create_text(&ndef_email_record, email, "en-US", NFC_ENCODE_UTF_8);
+</pre>
+</li>
+<li>
+<p>Create an NDEF message and append the records to the message:</p>
+
+<pre class="prettyprint">
+nfc_ndef_message_h ndef_message = NULL;
+nfc_ndef_message_create(&ndef_message);
+
+nfc_ndef_message_append_record(ndef_message, ndef_name_record);
+nfc_ndef_message_append_record(ndef_message, ndef_phone_record);
+nfc_ndef_message_append_record(ndef_message, ndef_email_record);
+</pre>
+</li></ol>
+</li>
+<li>Register callbacks to receive notifications about discovered P2P targets and the received data:
+<ul>
+<li>To exchange messages using P2P, register a callback for receiving notifications about discovered P2P targets. When the P2P target is discovered, the callback provides a handle to that device and information on whether it is attached or detached.</li>
+<li>Register a callback for receiving notifications about received data using the <span style="font-family: Courier New,Courier,monospace">nfc_p2p_set_data_received_cb()</span> function. Place the registration code in the callback called after the P2P device is discovered.</li>
+</ul>
+
+<pre class="prettyprint">
+nfc_manager_set_p2p_target_discovered_cb(on_target_discovered, NULL);
+
+nfc_p2p_set_data_received_cb(target, on_p2p_data_received, NULL);
+</pre>
+</li>
+<li>Exchange messages:
+<ul>
+<li>Send a message to another device.
+<p>When the other P2P device is attached, send the prepared message to it. You can use the <span style="font-family: Courier New,Courier,monospace">nfc_p2p_send()</span> function, if you do not want to check permissions.</p>
+
+<pre class="prettyprint">
+nfc_p2p_send(target, ndef_message, NULL, NULL);
+</pre>
+</li>
+<li>Receive a message from another device.
+<p>The callback about receiving data is invoked when the device receives a message. The callback provides a handle to the received message and a handle to the message source.</p>
+<p>To get a specified record from the message, use the <span style="font-family: Courier New,Courier,monospace">nfc_ndef_message_get_record()</span> function with the parameters for a message handle, a record index, and a handle to store the obtained record. When the record is obtained, get the stored text using the <span style="font-family: Courier New,Courier,monospace">nfc_ndef_record_get_text()</span> function.</p>
+
+<pre class="prettyprint">
+nfc_ndef_record_h ndef_record;
+
+char *name = NULL;
+nfc_ndef_message_get_record(message, 0, &ndef_record);
+nfc_ndef_record_get_text(ndef_record, &name);
+
+char *phone = NULL;
+nfc_ndef_message_get_record(message, 1, &ndef_record);
+nfc_ndef_record_get_text(ndef_record, &phone);
+
+char *email = NULL;
+nfc_ndef_message_get_record(message, 2, &ndef_record);
+nfc_ndef_record_get_text(ndef_record, &email);
+</pre>
+</li></ul>
+</li>
+</ol>
+
+<script type="text/javascript" src="../../scripts/jquery.zclip.min.js"></script>
+<script type="text/javascript" src="../../scripts/showhide.js"></script>
+</div></div></div>
+
+<a class="top sms" href="#"><img src="../../images/btn_top.gif" alt="Go to top" /></a>
+
+<div id="footer">
+<p class="footer">Except as noted, this content - excluding the Code Examples - is licensed under <a href="http://creativecommons.org/licenses/by/3.0/legalcode" target="_blank">Creative Commons Attribution 3.0</a> and all of the Code Examples contained herein are licensed under <a href="https://www.tizen.org/bsd-3-clause-license" target="_blank">BSD-3-Clause</a>.<br/>For details, see the <a href="https://www.tizen.org/content-license" target="_blank">Content License</a>.</p>
+</div>
+
+<script type="text/javascript">
+var _gaq = _gaq || [];
+_gaq.push(['_setAccount', 'UA-25976949-1']);
+_gaq.push(['_trackPageview']);
+(function() {
+var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+})();
+</script>
+
+</body>
+</html>
+
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <meta http-equiv="X-UA-Compatible" content="IE=9" />
+ <link rel="stylesheet" type="text/css" href="../../css/styles.css" />
+ <link rel="stylesheet" type="text/css" href="../../css/snippet.css" />
+ <script type="text/javascript" src="../../scripts/snippet.js"></script>
+ <script type="text/javascript" src="../../scripts/jquery.util.js" charset="utf-8"></script>
+ <script type="text/javascript" src="../../scripts/common.js" charset="utf-8"></script>
+ <script type="text/javascript" src="../../scripts/core.js" charset="utf-8"></script>
+ <script type="text/javascript" src="../../scripts/search.js" charset="utf-8"></script>
+
+ <title>Receiving Content from Other Applications</title>
+</head>
+
+<body onload="prettyPrint()" style="overflow: auto;">
+
+<div id="toc-navigation">
+ <div id="profile">
+ <p><img alt="Mobile native" src="../../images/mobile_s_n.png"/> <img alt="Wearable native" src="../../images/wearable_s_n.png"/></p>
+ </div>
+ <div id="toc_border"><div id="toc">
+ <p class="toc-title">Content</p>
+ <ul class="toc">
+ <li><a href="#export">Exporting Application Control Functionality</a></li>
+ <li><a href="#incoming">Handling Incoming Content</a></li>
+ <li><a href="#extra_data">Managing Extra Data</a></li>
+ </ul>
+ <p class="toc-title">Related Info</p>
+ <ul class="toc">
+ <li><a href="../../../../org.tizen.guides/html/native/app_management/app_controls_n.htm">Application Controls Guides</a></li>
+ <li><a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__APP__CONTROL__MODULE.html">App Control API for Mobile Native</a></li>
+ <li><a href="../../../../org.tizen.native.wearable.apireference/group__CAPI__APP__CONTROL__MODULE.html">App Control API for Wearable Native</a></li>
+ </ul>
+ </div></div>
+</div>
+<div id="container"><div id="contents"><div class="content">
+<h1>Receiving Content from Other Applications</h1>
+
+<p>The basic tasks involved in receiving content from other applications are advertising the features available in your application, handling the incoming content, and managing any extra data sent with the content. The following sections provide you with the fundamental building blocks for receiving content that other applications want to share with you.</p>
+
+<h2 id="export">Exporting Application Control Functionality</h2>
+
+<p>To allow other applications to find and use your application features implicitly without your application ID, you must advertise your application features to other applications. You can do this by declaring your application control information in the <span style="font-family: Courier New,Courier,monospace">tizen-manifest.xml</span> file.</p>
+
+<p>The following example shows an advertisement for the <span style="font-family: Courier New,Courier,monospace">VIEW</span> and <span style="font-family: Courier New,Courier,monospace">CALL</span> application control operations:</p>
+
+<pre class="prettyprint">
+<app-control>
+ <mime name = "application/xhtml+xml"/>
+ <operation name = "http://tizen.org/appcontrol/operation/view"/>
+ <uri name = "http"/>
+</app-control>
+<app-control>
+ <operation name = "http://tizen.org/appcontrol/operation/dial"/>
+ <uri name = "tel"/>
+</app-control>
+</pre>
+
+ <table class="note">
+ <tbody>
+ <tr>
+ <th class="note">Note</th>
+ </tr>
+ <tr>
+ <td class="note">In the application manifest file, the valid operation name format is <span style="font-family: Courier New,Courier,monospace">http://tizen.org/appcontrol/operation/<verb></span>. You cannot use the related macro name format: <span style="font-family: Courier New,Courier,monospace">APP_CONTROL_OPERATION_<VERB></span>.</td>
+ </tr>
+ </tbody>
+ </table>
+
+
+<h2 id="incoming">Handling Incoming Content</h2>
+
+<p>When another application sends an application control request to your application, the application framework calls your application's <span style="font-family: Courier New,Courier,monospace">app_control_cb()</span> callback just after your application enters the main loop. This callback is passed to the handler, <span style="font-family: Courier New,Courier,monospace">app_control</span>, containing the reason why your application was launched. For example, your application can be launched to open a file that another application is sharing with you.</p>
+
+<p>When an application control request arrives, your application is responsible for checking and responding accordingly to the information of the <span style="font-family: Courier New,Courier,monospace">app_control</span> handler.</p>
+
+<p>The following example shows how you can initialize the application to allow the application control callback to handle the request for the <span style="font-family: Courier New,Courier,monospace">APP_CONTROL_OPERATION_VIEW</span> operation:</p>
+
+<pre class="prettyprint">
+int
+main(int argc, char *argv[])
+{
+ struct appdata ad;
+
+ ui_app_lifecycle_callback_s event_callback;
+
+ event_callback.create = app_create;
+ event_callback.terminate = app_terminate;
+ event_callback.pause = app_pause;
+ event_callback.resume = app_resume;
+ /* Register the app control callback */
+ event_callback.app_control = app_control;
+
+ memset(&ad, 0x0, sizeof(struct appdata));
+
+ return ui_app_main(argc, argv, &event_callback, &ad);
+}
+
+/* App control callback */
+static void
+app_control(app_control_h app_control, void *user_data)
+{
+ struct appdata *ad = (struct appdata *)user_data;
+ char *operation;
+ char *uri;
+ char *mime_type;
+
+ app_control_get_operation(app_control, operation);
+
+ if (!strcmp(operation, APP_CONTROL_OPERATION_VIEW)) {
+ app_control_get_uri(app_control, &uri);
+ app_control_get_mime(app_control, &mime_type);
+
+ if (uri && !strcmp(mime_type, "image/jpg"))
+ /* Display the image file the other application is sharing with you */
+ display_image_file(ad, uri);
+ }
+
+ if (ad->win)
+ elm_win_activate(ad->win);
+}
+</pre>
+
+<h2 id="extra_data">Managing Extra Data</h2>
+
+<p>Using the <span style="font-family: Courier New,Courier,monospace">app_control_foreach_extra_data()</span> function, you can read any extra data added to the <span style="font-family: Courier New,Courier,monospace">app_control</span> handle. This function calls the <span style="font-family: Courier New,Courier,monospace">_app_control_extra_data_cb()</span> callback once for each extra data key-value pair contained in the handle. When the callback returns <span style="font-family: Courier New,Courier,monospace">false</span>, the iteration ends.</p>
+
+<pre class="prettyprint">
+bool
+_app_control_extra_data_cb(app_control_h app, const char *key, void *user_data)
+{
+ int ret;
+ char *value;
+
+ ret = app_control_get_extra_data(app, key, &value);
+ if (ret == APP_CONTROL_ERROR_NONE)
+ dlog_print(DLOG_DEBUG, LOG_TAG, "[value] %s", value);
+ else
+ dlog_print(DLOG_ERROR, LOG_TAG, "app_control_get_extra_data() failed. err = %d", ret);
+
+ return true;
+}
+
+ret = app_control_foreach_extra_data(app, _app_control_extra_data_cb, 0);
+if (ret != APP_CONTROL_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "app_control_foreach_extra_data() failed. err = %d", ret);
+</pre>
+
+<script type="text/javascript" src="../../scripts/jquery.zclip.min.js"></script>
+<script type="text/javascript" src="../../scripts/showhide.js"></script>
+</div></div></div>
+
+<a class="top sms" href="#"><img src="../../images/btn_top.gif" alt="Go to top" /></a>
+
+<div id="footer">
+<p class="footer">Except as noted, this content - excluding the Code Examples - is licensed under <a href="http://creativecommons.org/licenses/by/3.0/legalcode" target="_blank">Creative Commons Attribution 3.0</a> and all of the Code Examples contained herein are licensed under <a href="https://www.tizen.org/bsd-3-clause-license" target="_blank">BSD-3-Clause</a>.<br/>For details, see the <a href="https://www.tizen.org/content-license" target="_blank">Content License</a>.</p>
+</div>
+
+<script type="text/javascript">
+var _gaq = _gaq || [];
+_gaq.push(['_setAccount', 'UA-25976949-1']);
+_gaq.push(['_trackPageview']);
+(function() {
+var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+})();
+</script>
+
+</body>
+</html>
+
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <meta http-equiv="X-UA-Compatible" content="IE=9" />
+ <link rel="stylesheet" type="text/css" href="../../css/styles.css" />
+ <link rel="stylesheet" type="text/css" href="../../css/snippet.css" />
+ <script type="text/javascript" src="../../scripts/snippet.js"></script>
+ <script type="text/javascript" src="../../scripts/jquery.util.js" charset="utf-8"></script>
+ <script type="text/javascript" src="../../scripts/common.js" charset="utf-8"></script>
+ <script type="text/javascript" src="../../scripts/core.js" charset="utf-8"></script>
+ <script type="text/javascript" src="../../scripts/search.js" charset="utf-8"></script>
+
+ <title>Sending Content to Other Applications</title>
+</head>
+
+<body onload="prettyPrint()" style="overflow: auto;">
+
+<div id="toc-navigation">
+ <div id="profile">
+ <p><img alt="Mobile native" src="../../images/mobile_s_n.png"/> <img alt="Wearable native" src="../../images/wearable_s_n.png"/></p>
+ </div>
+ <div id="toc_border"><div id="toc">
+ <p class="toc-title">Content</p>
+ <ul class="toc">
+ <li><a href="#text">Sending Text</a></li>
+ <li><a href="#binaries">Sending Binaries</a></li>
+ <li><a href="#files">Sending Files</a></li>
+ </ul>
+ <p class="toc-title">Related Info</p>
+ <ul class="toc">
+ <li><a href="../../../../org.tizen.guides/html/native/app_management/app_controls_n.htm">Application Controls Guides</a></li>
+ <li><a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__APP__CONTROL__MODULE.html">App Control API for Mobile Native</a></li>
+ <li><a href="../../../../org.tizen.native.wearable.apireference/group__CAPI__APP__CONTROL__MODULE.html">App Control API for Wearable Native</a></li>
+ </ul>
+ </div></div>
+</div>
+<div id="container"><div id="contents"><div class="content">
+<h1>Sending Content to Other Applications</h1>
+
+<p>You can send various types of content to other applications, including text, binaries, and files. The following sections provide you with the fundamental building blocks for sharing your application data with other applications.</p>
+
+<h2 id="text">Sending Text</h2>
+
+<p>The most common content sharing use case is sending text to another application. For example, a Web browser can share the URL of the currently visited site with other applications, such as a messenger or email application, to allow the user to send the URL to their friends.</p>
+
+<p>Use the <span style="font-family: Courier New,Courier,monospace">APP_CONTROL_OPERATION_SHARE</span> operation and the <span style="font-family: Courier New,Courier,monospace">text/plain</span> MIME type to create an application control request, and define the text content to be shared in the <span style="font-family: Courier New,Courier,monospace">APP_CONTROL_DATA_TEXT</span> extra data:</p>
+
+<pre class="prettyprint">
+#include <app_control.h>
+
+app_control_h app_control;
+
+app_control_create(&app_control);
+
+app_control_set_operation(app_control, APP_CONTROL_OPERATION_SHARE);
+app_control_set_mime(app_control, "text/plain");
+app_control_add_extra_data(app_control, APP_CONTROL_DATA_TEXT, "Hello, World!");
+
+app_control_send_launch_request(app_control, NULL, NULL);
+</pre>
+
+<p>The above example has no explicit designation of the application to be called. When you request an implicit launch, the application launcher framework determines which application to launch by comparing the conditions: operation, URI (or scheme), and MIME type. If only one application is found to match the given conditions, that application is launched. If multiple matching applications are found, the application selector is shown and the user can select the application they want.</p>
+
+
+ <table class="note">
+ <tbody>
+ <tr>
+ <th class="note">Note</th>
+ </tr>
+ <tr>
+ <td class="note">When using application controls, pay attention to the following:
+ <ul>
+ <li>Since Tizen 2.4, application controls that launch <a href="../../../../org.tizen.guides/html/native/app_management/service_app_n.htm">service applications</a> outside the current package are not supported. Because of this, a service application can only be launched explicitly by an application in the same package.</li>
+ <li>The operation is mandatory information for sending a launch request. If the operation is not specified, the <span style="font-family: Courier New,Courier,monospace">APP_CONTROL_OPERATION_DEFAULT</span> operation is used. In that case, the application ID is mandatory to explicitly launch an application.</li>
+ </ul></td>
+ </tr>
+ </tbody>
+ </table>
+
+<h2 id="binaries">Sending Binaries</h2>
+
+<p>Depending on the number of binary content items to be shared, you can use the <span style="font-family: Courier New,Courier,monospace">APP_CONTROL_OPERATION_SHARE</span> (for a single item) or <span style="font-family: Courier New,Courier,monospace">APP_CONTROL_OPERATION_MULTI_SHARE</span> (for multiple items) operation. The location of the content to be shared is defined in the <span style="font-family: Courier New,Courier,monospace">APP_CONTROL_DATA_PATH</span> extra data or extra data array.</p>
+
+<p>The following example demonstrates how to share a single binary content item and multiple items:</p>
+
+<pre class="prettyprint">
+/* Single item */
+#define PATH_MAX 128
+
+char *shared_res_path = app_get_shared_resource_path();
+char img_path[PATH_MAX] = {0,};
+snprintf(img_path, PATH_MAX, "%s/image.jpg", shared_res_path);
+free(shared_res_path);
+
+app_control_h service;
+app_control_create(&service);
+
+app_control_set_operation(service, APP_CONTROL_OPERATION_SHARE);
+app_control_set_mime(service, "image/*");
+app_control_add_extra_data(service, APP_CONTROL_DATA_PATH, img_path);
+app_control_set_launch_mode(service, APP_CONTROL_LAUNCH_MODE_GROUP);
+
+app_control_send_launch_request(service, NULL, NULL);
+app_control_destroy(service);
+
+/* Multiple items */
+#define PATH_MAX 128
+
+char *shared_res_path = app_get_shared_resource_path();
+char img1_path[PATH_MAX] = {0,};
+char img2_path[PATH_MAX] = {0,};
+const char *path_array[2] = {img1_path, img2_path};
+snprintf(img1_path, PATH_MAX, "%s/image.jpg", shared_res_path);
+snprintf(img2_path, PATH_MAX, "%s/image2.jpg", shared_res_path);
+free(shared_res_path);
+
+app_control_h service;
+app_control_create(&service);
+
+app_control_set_operation(service, APP_CONTROL_OPERATION_MULTI_SHARE);
+app_control_set_mime(service, "image/*");
+app_control_add_extra_data_array(service, APP_CONTROL_DATA_PATH, path_array, 2);
+app_control_set_launch_mode(service, APP_CONTROL_LAUNCH_MODE_GROUP);
+
+app_control_send_launch_request(service, NULL, NULL);
+app_control_destroy(service);
+</pre>
+
+<p>If you try to share a set of files with different MIME types, use <span style="font-family: Courier New,Courier,monospace"><type>/*</span> or <span style="font-family: Courier New,Courier,monospace">*/*</span>. For example, if you send <span style="font-family: Courier New,Courier,monospace">video/mp4</span> and <span style="font-family: Courier New,Courier,monospace">audio/ogg</span>, the MIME type must be <span style="font-family: Courier New,Courier,monospace">*/*</span>.</p>
+
+
+<h2 id="files">Sending Files</h2>
+
+<p>When sharing files, you can use the <span style="font-family: Courier New,Courier,monospace">app_control_set_uri()</span> function to set the file URI with the <span style="font-family: Courier New,Courier,monospace">file://</span> scheme.</p>
+<p>Since Tizen 2.4, if the second parameter of the <span style="font-family: Courier New,Courier,monospace">app_control_set_uri()</span> function starts with <span style="font-family: Courier New,Courier,monospace">file://</span>, and it is a regular file in your application's data path which can be obtained by calling the <span style="font-family: Courier New,Courier,monospace">app_get_data_path()</span> function, the file is shared with the called application. The framework grants a temporary permission to the called application for this file, and revokes it when the called application is terminated. The called application can just read the file.</p>
+
+<p>The following example launches a viewer application with the operation, URI, and MIME type:</p>
+
+<pre class="prettyprint">
+#include <app.h>
+#include <dlog.h>
+
+#define TAG "MY_TAG"
+#define PATH_MAX 128
+
+app_control_h app_control;
+char* data_path = app_get_data_path();
+
+char file_path[PATH_MAX] = {0,};
+snprintf(file_path, PATH_MAX, "%s/image.jpg", data_path);
+free(data_path);
+
+app_control_create(&app_control);
+app_control_set_operation(app_control, APP_CONTROL_OPERATION_VIEW);
+app_control_set_uri(app_control, file_path);
+app_control_set_mime(app_control, "image/*");
+
+if (app_control_send_launch_request(app_control, NULL, NULL) == APP_CONTROL_ERROR_NONE)
+ dlog_print(DLOG_INFO, TAG, "Succeeded to launch a viewer app.");
+else
+ dlog_print(DLOG_ERROR, TAG, "Failed to launch a viewer app.");
+
+app_control_destroy(app_control);
+</pre>
+
+
+<script type="text/javascript" src="../../scripts/jquery.zclip.min.js"></script>
+<script type="text/javascript" src="../../scripts/showhide.js"></script>
+</div></div></div>
+
+<a class="top sms" href="#"><img src="../../images/btn_top.gif" alt="Go to top" /></a>
+
+<div id="footer">
+<p class="footer">Except as noted, this content - excluding the Code Examples - is licensed under <a href="http://creativecommons.org/licenses/by/3.0/legalcode" target="_blank">Creative Commons Attribution 3.0</a> and all of the Code Examples contained herein are licensed under <a href="https://www.tizen.org/bsd-3-clause-license" target="_blank">BSD-3-Clause</a>.<br/>For details, see the <a href="https://www.tizen.org/content-license" target="_blank">Content License</a>.</p>
+</div>
+
+<script type="text/javascript">
+var _gaq = _gaq || [];
+_gaq.push(['_setAccount', 'UA-25976949-1']);
+_gaq.push(['_trackPageview']);
+(function() {
+var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+})();
+</script>
+
+</body>
+</html>
+
<topic href="html/native/feature/app_connectivity_usage_n.htm" label="Network Usage"></topic>
<topic href="html/native/feature/app_connectivity_p2p_n.htm" label="P2P Connections with Wi-Fi Direct™"></topic>
</topic>
+ <topic href="html/native/feature/app_contacts_n.htm" label="Creating Applications with Contacts">
+ <topic href="html/native/feature/app_contacts_basic_n.htm" label="Basic Concepts"></topic>
+ <topic href="html/native/feature/app_contacts_management_n.htm" label="Contact Management"></topic>
+ <topic href="html/native/feature/app_contacts_group_n.htm" label="Group Management"></topic>
+ </topic>
+ <topic href="html/native/feature/app_contentshare_n.htm" label="Creating Applications with Content Sharing">
+ <topic href="html/native/feature/app_contentshare_send_n.htm" label="Sending Content to Other Applications"></topic>
+ <topic href="html/native/feature/app_contentshare_receive_n.htm" label="Receiving Content from Other Applications"></topic>
+ <topic href="html/native/feature/app_contentshare_nfc_n.htm" label="Sharing through NFC"></topic>
+ </topic>
<topic href="html/native/feature/app_graphics_n.htm" label="Creating Applications with Graphics and Animation">
<topic href="html/native/feature/app_graphics_square_n.htm" label="Squares on the Canvas"></topic>
<topic href="html/native/feature/app_graphics_polygon_n.htm" label="Polygons on the Canvas"></topic>