Tutorials for Contextual History and Trigger APIs
authorMu-Woong Lee <muwoong.lee@samsung.com>
Wed, 8 Apr 2015 05:53:19 +0000 (14:53 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Wed, 8 Apr 2015 05:53:19 +0000 (14:53 +0900)
Change-Id: I3c769d86ded6edc0ec67e8c9c29ca1b5ef6679c1
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
org.tizen.tutorials/html/native/context/context_tutorials_n.htm
org.tizen.tutorials/html/native/context/history_tutorial_n.htm [new file with mode: 0644]
org.tizen.tutorials/html/native/context/trigger_tutorial_n.htm [new file with mode: 0644]

index 55ba2d5..91e20c9 100644 (file)
@@ -19,7 +19,7 @@
         <p><img alt="Mobile native" src="../../images/mn_icon.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/context/context_guide_n.htm">Context Guides</a></li>
 
 <div id="container"><div id="contents"><div class="content">
 
- <h1>Context: Detecting and Exploiting Contextual Information</h1>
+<h1>Context: Detecting and Exploiting Contextual Information</h1>
 
- <p>The context tutorials demonstrate how to use the following features in creating Tizen mobile native applications:</p>
-  <ul>
-   
-   <li><a href="activity_tutorial_n.htm">Activity Recognition: Detecting Device Activities</a> <p>Demonstrates how you can detect user activities.</p></li>
-   <li><a href="gesture_tutorial_n.htm">Gesture Recognition: Detecting Device Gestures</a> <p>Demonstrates how you can detect gestures performed with the device.</p></li>
-  </ul>
+<p>The context tutorials demonstrate how to use the following features in creating Tizen mobile native applications:</p>
+<ul>
+       <li><a href="activity_tutorial_n.htm">Activity Recognition: Detecting User Activities</a>
+               <p>Demonstrates how you can detect user activities.</p></li>
+       <li><a href="gesture_tutorial_n.htm">Gesture Recognition: Detecting User Gestures</a>
+               <p>Demonstrates how you can detect gestures performed with the device.</p></li>
+       <li><a href="trigger_tutorial_n.htm">Contextual Trigger: Context-aware Task Automation</a>
+               <p>Demonstrates how you can automate your tasks, by monitoring contextual events and conditions detected on the device.</p></li>
+       <li><a href="history_tutorial_n.htm">Contextual Trigger: Getting the Device Usage Profiles</a>
+               <p>Demonstrates how you can retrieve the device usage profiles analyzed from the usage history of the device.</p></li>
+</ul>
 
 
 <script type="text/javascript" src="../../scripts/jquery.zclip.min.js"></script>
@@ -63,4 +68,4 @@ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga
 </script>
 
 </body>
-</html>
\ No newline at end of file
+</html>
diff --git a/org.tizen.tutorials/html/native/context/history_tutorial_n.htm b/org.tizen.tutorials/html/native/context/history_tutorial_n.htm
new file mode 100644 (file)
index 0000000..47e2d1a
--- /dev/null
@@ -0,0 +1,215 @@
+<!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>Contextual History Tutorial</title>
+</head>
+<body onload="prettyPrint()" style="overflow: auto;">
+
+<div id="navigation">
+       <div id="profile">
+               <p><img alt="Mobile native" src="../../images/mn_icon.png"/></p>
+       </div>
+       <div id="toc_border"><div id="toc">
+               <p class="toc-title">Content</p>
+               <ul class="toc">
+                       <li><a href="#get_list" class="opensection">Getting a List of Data Records</a>
+                       <li><a href="#enumerate_list" class="opensection">Enumerating a List of Data Records</a>
+               </ul>
+               <p class="toc-title">Related Info</p>
+               <ul class="toc">
+                       <li><a href="../../../../org.tizen.guides/html/native/context/history_n.htm">Contextual History Guide</a></li>
+                       <li><a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__CONTEXT__HISTORY__MODULE.html">Contextual History API</a></li>
+               </ul>
+       </div></div>
+</div>
+
+<div id="container"><div id="contents"><div class="content">
+
+<h1>Contextual History Tutorial</h1>
+<div class="cont"><div class="static-cont">
+
+<p>
+This tutorial demonstrates how to get the history profiles of the device usages, and enumerate data lists retrieved.
+</p>
+<p>
+To learn about the <a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__CONTEXT__HISTORY__MODULE.html">Contextual History</a> API features,
+see the <a href="../../../../org.tizen.guides/html/native/context/history_n.htm">Contextual History Programming Guide</a>.
+</p>
+<p>
+This tutorial consists of the following parts:
+</p>
+<ul>
+       <li><a href="#get_list" class="opensection">Getting a List of Data Records</a>
+               <p>It will show how to get the history profiles of the device usages.
+               A history profile retrieved via this API is formulated as a list of data records.</p></li>
+       <li><a href="#enumerate_list" class="opensection">Enumerating a List of Data Records</a>
+               <p>It will show how to enumerate the records contained in the list obtained in the previous step.</p></li>
+</ul>
+
+<div class="devicespecs-util mt5 clfix">
+       <ul class="dutil">
+               <li><a href="#" class="showA">Show All</a></li>
+               <li class="none"><a href="#" class="hideA">Hide All</a></li>
+       </ul>
+</div>
+
+<!-- Folds -->
+<ul class="devicespecifications">
+
+       <li>
+               <div class="devicespec-tit">
+                       <h2 id="get_list" name="get_list" class="items-tit-h2">Getting a List of Data Records</h2>
+                       <span class="fr"><a href="#" class="bt-arr"><em>Hide</em></a></span>
+               </div>
+               <div class="devicespec-con">
+                       <p>
+                       To retrieve a contextual history profile, for example,
+                       <span style="font-family: Courier New,Courier,monospace;">CONTEXT_HISTORY_FREQUENTLY_USED_APP</span>,
+                       a <em>filter</em> needs to be set to specify the data to retrieve, then the profile can be obtained
+                       using <span style="font-family: Courier New,Courier,monospace;">context_history_get_list()</span>.
+                       </p>
+                       <ol>
+                               <li>The following header needs to be included in advance.
+<pre class="prettyprint">
+#include &lt;context_history.h&gt;
+</pre>
+                               </li>
+                               <li>To get a history profile, two handles, one for using the contextual history API and one for the filter, are created.
+<pre class="prettyprint">
+// Creating a handle for using the contextual history API
+context_history_h handle;
+context_history_create(&handle);
+
+// Creating a filter handle
+context_history_filter_h filter;
+context_history_filter_create(&filter);
+</pre>
+                               </li>
+                               <li>The filter handle needs to be properly configured. In this example, we will get the top-5 frequently used applications,
+                                       by only considering the applications used while a headphone is connected, during the last 2 weeks (14 days).
+<pre class="prettyprint">
+// Requesting the top-5 applications
+context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_RESULT_SIZE, 5);
+
+// Limiting the time span of usage logs to 14 days
+context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_TIME_SPAN, 14);
+
+// Considering the applications used while a headphone is connected
+context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_AUDIO_JACK, CONTEXT_HISTORY_FILTER_AUDIO_JACK_CONNECTED);
+</pre>
+                               </li>
+                               <li>Then with that filter, the list of the top-5 applications can be retrieved as follows.
+<pre class="prettyprint">
+context_history_list_h list;
+
+// Getting the list of records
+context_history_get_list(handle, CONTEXT_HISTORY_FREQUENTLY_USED_APP, filter, &list);
+
+// The filter needs to be released explicitly.
+context_history_filter_destroy(filter);
+</pre>
+                               </li>
+                       </ol>
+               </div>
+       </li>
+
+       <li>
+               <div class="devicespec-tit">
+                       <h2 id="enumerate_list" name="enumerate_list" class="items-tit-h2">Enumerating a List of Data Records</h2>
+                       <span class="fr"><a href="#" class="bt-arr"><em>Hide</em></a></span>
+               </div>
+               <div class="devicespec-con">
+                       <p>
+                       The <span style="font-family: Courier New,Courier,monospace;">list</span> retrieved via
+                       <span style="font-family: Courier New,Courier,monospace;">context_history_get_list()</span> contains
+                       a sort listed of the records, each of which consists of the pairs of keys and values.
+                       This list can be enumerated as follows.
+                       </p>
+                       <ol>
+                               <li>In some cases, the retrieve list may contain less records than the result size set in the filter.
+                                       The actual number of records contained in the list can be checked before enumerating the list.
+<pre class="prettyprint">
+int size;
+context_history_list_get_count(list, &size);
+</pre>
+                               </li>
+                               <li>Then, the list can be enumerated using a loop.
+<pre class="prettyprint">
+int i, count;
+char* app_id;
+context_history_record_h record;
+
+for (i = 0; i < size; ++i)
+{
+       // Getting the current record
+       context_history_list_get_current(list, &record);
+
+       // Retrieving the application ID and the total used count from the record
+       context_history_record_get_string(record, CONTEXT_HISTORY_APP_ID, &app_id);
+       context_history_record_get_int(record, CONTEXT_HISTORY_TOTAL_COUNT, &count);
+
+       // ...
+
+       // Freeing the application ID string
+       free(app_id);
+
+       // Releasing the memory occupied by the record
+       context_history_record_destroy(record);
+
+       // Iterating to the next record
+       context_history_list_move_next(list);
+}
+</pre>
+                               <li>After the enumeration, the list needs to be released to prevent any resource leaks.
+<pre class="prettyprint">
+context_history_list_destroy(list);
+</pre>
+                               </li>
+                               <li>Finally, the <span style="font-family: Courier New,Courier,monospace;">handle</span> should be released,
+                                       if it will not be used anymore.
+<pre class="prettyprint">
+context_history_destroy(handle);
+</pre>
+                               </li>
+                       </ol>
+               </div>
+       </li>
+
+</ul>
+
+</div>
+</div>
+
+<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>
diff --git a/org.tizen.tutorials/html/native/context/trigger_tutorial_n.htm b/org.tizen.tutorials/html/native/context/trigger_tutorial_n.htm
new file mode 100644 (file)
index 0000000..fd56ade
--- /dev/null
@@ -0,0 +1,376 @@
+<!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>Contextual Trigger Tutorial</title>
+ </head>
+<body onload="prettyPrint()" style="overflow: auto;">
+
+<div id="navigation">
+    <div id="profile">
+        <p><img alt="Mobile native" src="../../images/mn_icon.png"/></p>
+    </div>
+    <div id="toc_border"><div id="toc">
+               <p class="toc-title">Content</p>
+               <ul class="toc">
+                       <li>Composing a Rule</li>
+                       <ul>
+                               <li><a href="#create_rule">Creating a Rule</a></li>
+                               <li><a href="#create_event" class="opensection">Creating an Event</a></li>
+                               <li><a href="#create_condition" class="opensection">Creating Conditions</a></li>
+                               <li><a href="#set_action" class="opensection">Setting an Action</a></li>
+                       </ul>
+                       <li>Managing Rules</li>
+                       <ul>
+                               <li><a href="#add_rule" class="opensection">Adding a Rule</a></li>
+                               <li><a href="#enable_rule" class="opensection">Enabling a Rule</a></li>
+                               <li><a href="#disable_rule" class="opensection">Disabling a Rule</a></li>
+                               <li><a href="#remove_rule" class="opensection">Removing a Rule</a></li>
+                       </ul>
+                       <li><a href="#retrieve_rule" class="opensection">Retrieving Rules</a></li>
+               </ul>
+               <p class="toc-title">Related Info</p>
+               <ul class="toc">
+                       <li><a href="../../../../org.tizen.guides/html/native/context/trigger_n.htm">Contextual Trigger Guide</a></li>
+                       <li><a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__CONTEXT__TRIGGER__MODULE.html">Contextual Trigger API</a></li>
+               </ul>
+       </div></div>
+</div>
+
+<div id="container"><div id="contents"><div class="content">
+
+ <h1>Contextual Trigger Tutorial</h1>
+<div class="cont"><div class="static-cont">
+
+  <p>This tutorial demonstrates how to compose rules based on context states and manage them.</p>
+  <p>To learn about the <a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__CONTEXT__TRIGGER__MODULE.html">Contextual Trigger</a> API features, see the <a href="../../../../org.tizen.guides/html/native/context/trigger_n.htm">Contextual Trigger Programming Guide</a>.</p>
+  <p>This tutorial consists of the following parts:</p>
+  <ul>
+       <li>Composing Rules</li>
+       <ul>
+               <li><a href="#create_rule">Creating a Rule</a><p>Create a new rule and set its description.</p></li>
+               <li><a href="#create_event" class="opensection">Creating an Event</a><p>Create an event and add it to the rule.</p></li>
+               <li><a href="#create_condition" class="opensection">Creating Conditions</a><p>Create conditions and add them to the rule.</p></li>
+               <li><a href="#set_action" class="opensection">Setting an Action</a><p>Set an action, such as notification posting or application launching.</p></li>
+       </ul>
+       <li>Managing Rules</li>
+       <ul>
+               <li><a href="#add_rule" class="opensection">Adding a Rule</a><p>Add a new rule and release resources.</p></li>
+               <li><a href="#enable_rule" class="opensection">Enabling a Rule</a><p>Enable a rule to activate it.</p></li>
+               <li><a href="#disable_rule" class="opensection">Disabling a Rule</a><p>Disable a rule to deactivate it.</p></li>
+               <li><a href="#remove_rule" class="opensection">Removing a Rule</a><p>Remove a rule if it is no longer needed.</p></li>
+       </ul>
+       <li><a href="#retrieve_rule" class="opensection">Retrieving Rules</a><p>Retrieve rules created by your application.</p></li>
+  </ul>
+
+
+<div class="devicespecs-util mt5 clfix">
+               <ul class="dutil">
+                       <li><a href="#" class="showA">Show All</a></li>
+                       <li class="none"><a href="#" class="hideA">Hide All</a></li>
+               </ul>
+       </div>
+       <!-- Folds -->
+       <ul class="devicespecifications">
+
+               <li>
+                       <div class="devicespec-tit">
+                               <h2 id="create_rule" name="create_rule" class="items-tit-h2">Creating a Rule</h2>
+                               <span class="fr"><a href="#" class="bt-arr"><em>Hide</em></a></span>
+                       </div>
+                       <div class="devicespec-con">
+
+<p>To use Contextual Trigger API, your application needs to compose a rule. As a case study, the below example code illustrates how to create a rule, which can be described as "Notify if battery is not charging and either WiFi or GPS is enabled when battery level becomes too low". We will use <span style="font-family: Courier New,Courier,monospace;">CONTEXT_TRIGGER_EVENT_BATTERY</span> as an event, and <span style="font-family: Courier New,Courier,monospace;">CONTEXT_TRIGGER_CONDITION_WIFI</span>, and <span style="font-family: Courier New,Courier,monospace;">CONTEXT_TRIGGER_CONDITION_GPS</span> as conditions.</p>
+<ol>
+<li>
+<p>To use the contextual trigger related features of the <a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__CONTEXT__TRIGGER__MODULE.html">Contextual Trigger</a> API, include the <span style="font-family: Courier New,Courier,monospace;">&lt;context_trigger.h&gt;</span> header file in your application:</p>
+<pre class="prettyprint">
+#include &lt;context_trigger.h&gt;
+</pre>
+</li>
+<li>Create a rule handle using the <span style="font-family: Courier New,Courier,monospace;">context_trigger_rule_create()</span> function. While creating a rule handle, the application chooses the logical operator, logical conjunction or disjunction, which will be applied to combine the conditions. WiFi and GPS conditions shouldn't be satisfied at the same time. Thus, the rule should be created with the <span style="font-family: Courier New,Courier,monospace;">CONTEXT_TRIGGER_LOGICAL_DISJUNCTION</span>.
+<pre class="prettyprint">
+context_trigger_rule_h rule = NULL;
+context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_DISJUNCTION, &amp;rule);
+</pre>
+</li>
+<li>Your application is able to set description in human language. Note that setting description is not mandatory.
+<pre class="prettyprint">
+context_trigger_rule_set_description(rule, "Notify if battery is not charging and either WiFi or GPS is enabled when battery level becomes too low");
+</pre>
+</li>
+</ol>
+                       </div>
+               </li>
+
+               <li>
+                       <div class="devicespec-tit">
+                               <h2 id="create_event" name="create_event" class="items-tit-h2">Creating an Event</h2>
+                               <span class="fr"><a href="#" class="bt-arr"><em>Hide</em></a></span>
+                       </div>
+                       <div class="devicespec-con">
+
+<p>Now, we need to create an <span style="font-family: Courier New,Courier,monospace;">CONTEXT_TRIGGER_EVENT_BATTERY</span> event to detect battery level changes.</p>
+<ol>
+<li>
+<p>Create an event handle using the <span style="font-family: Courier New,Courier,monospace;">context_trigger_rule_event_create()</span> function. </p>
+<pre class="prettyprint">
+context_trigger_rule_entry_h battery_event = NULL;
+context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_BATTERY, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &battery_event);
+</pre>
+<p>While creating an event handle, the application chooses the logical operator, logical conjunction or disjunction, which will be applied to combine the attribute keys for the event. In case of the event <span style="font-family: Courier New,Courier,monospace;">CONTEXT_TRIGGER_EVENT_BATTERY</span>, two types of contextual states are provided: <span style="font-family: Courier New,Courier,monospace;">CONTEXT_TRIGGER_LEVEL</span> and <span style="font-family: Courier New,Courier,monospace;">CONTEXT_TRIGGER_IS_CHARGING</span>. And now, the application wants to check both if battery level becomes too low and if battery is not charging. Thus, <span style="font-family: Courier New,Courier,monospace;">CONTEXT_TRIGGER_LOGICAL_CONJUNCTION</span> should be applied.</p>
+</li>
+<li>To specify detailed comparison terms for the event, the attribute key must be added in advance with the <span style="font-family: Courier New,Courier,monospace;">context_trigger_rule_entry_add_key()</span> function.
+<pre class="prettyprint">
+// Add CONTEXT_TRIGGER_LEVEL key
+context_trigger_rule_entry_add_key(battery_event, CONTEXT_TRIGGER_LOGICAL_DISJUNCTION, CONTEXT_TRIGGER_LEVEL);
+
+// Add CONTEXT_TRIGGER_IS_CHARGING key
+context_trigger_rule_entry_add_key(battery_event, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, CONTEXT_TRIGGER_IS_CHARGING);
+</pre>
+<p>For the battery level, the application wants to check whether the battery level becomes either one of low, empty or critical. For this reason, <span style="font-family: Courier New,Courier,monospace;">CONTEXT_TRIGGER_LEVEL</span> key should be added with the logical operator <span style="font-family: Courier New,Courier,monospace;">CONTEXT_TRIGGER_LOGICAL_DISJUNCTION</span>.</p>
+</li>
+<li>And then, the application can add comparison opeator and value for the attribute key with the <span style="font-family: Courier New,Courier,monospace;">context_trigger_rule_entry_add_comparison_int()</span> function or the <span style="font-family: Courier New,Courier,monospace;">context_trigger_rule_entry_add_string()</span> function depending on the data type.
+<pre class="prettyprint">
+// Add comparison values for the CONTEXT_TRIGGER_LEVEL key
+context_trigger_rule_entry_add_comparison_string(battery_event, CONTEXT_TRIGGER_LEVEL, CONTEXT_TRIGGER_EQUAL_TO, CONTEXT_TRIGGER_LOW);
+context_trigger_rule_entry_add_comparison_string(battery_event, CONTEXT_TRIGGER_LEVEL, CONTEXT_TRIGGER_EQUAL_TO, CONTEXT_TRIGGER_CRITICAL);
+context_trigger_rule_entry_add_comparison_string(battery_event, CONTEXT_TRIGGER_LEVEL, CONTEXT_TRIGGER_EQUAL_TO, CONTEXT_TRIGGER_EMPTY);
+
+// Add comparison value for the CONTEXT_TRIGGER_IS_CHARGING key
+context_trigger_rule_entry_add_comparison_int(battery_event, CONTEXT_TRIGGER_IS_CHARGING, CONTEXT_TRIGGER_EQUAL_TO, CONTEXT_TRIGGER_FALSE);
+</pre>
+</li>
+<li> After specifying comparison terms for the event, add the event entry to the rule. Note that a rule must include only one event.
+<pre class="prettyprint">
+context_trigger_rule_add_entry(rule, battery_event);
+</pre>
+</li>
+<li> Free the events.
+<pre class="prettyprint">
+context_trigger_rule_entry_destroy(battery_event);
+</pre>
+</li>
+</ol>
+                       </div>
+               </li>
+
+               <li>
+                       <div class="devicespec-tit">
+                               <h2 id="create_condition" name="create_condition" class="items-tit-h2">Creating Conditions</h2>
+                               <span class="fr"><a href="#" class="bt-arr"><em>Hide</em></a></span>
+                       </div>
+                       <div class="devicespec-con">
+
+<p>The below example describes how to create conditions to check WiFi and GPS states.</p>
+<ol>
+<li>
+<p>Create an event handle using the <span style="font-family: Courier New,Courier,monospace;">context_trigger_rule_condition_create()</span> function. </p>
+<pre class="prettyprint">
+// Create wifi condition
+context_trigger_rule_entry_h wifi_condition = NULL;
+context_trigger_rule_condition_create(CONTEXT_TRIGGER_CONDITION_WIFI, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &wifi_condition);
+
+// Create gps condition
+context_trigger_rule_entry_h gps_condition = NULL;
+context_trigger_rule_condition_create(CONTEXT_TRIGGER_CONDITION_GPS, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &gps_condition);
+</pre>
+</li>
+<li>Like events, the attribute key first needs to be added with the <span style="font-family: Courier New,Courier,monospace;">context_trigger_rule_entry_add_key()</span> function to specify comparison terms for each condition.
+<pre class="prettyprint">
+context_trigger_rule_entry_add_key(wifi_condition, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, CONTEXT_TRIGGER_STATE);
+context_trigger_rule_entry_add_key(gps_condition, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, CONTEXT_TRIGGER_STATE);
+</pre>
+</li>
+<li>After that, the application can add comparison opeator and value for the attribute key with the <span style="font-family: Courier New,Courier,monospace;">context_trigger_rule_entry_add_comparison_int()</span> function, the <span style="font-family: Courier New,Courier,monospace;">context_trigger_rule_entry_add_string()</span> function, or the <span style="font-family: Courier New,Courier,monospace;">context_trigger_rule_entry_add()</span> function depending on the data type. For more information, see the <a href="../../../../org.tizen.guides/html/native/context/trigger_n.htm">Contextual Trigger Programming Guide</a>. In the below code example, each condition check if WiFi/GPS state is not disabled.
+<pre class="prettyprint">
+context_trigger_rule_entry_add_comparison_string(wifi_condition, CONTEXT_TRIGGER_STATE, CONTEXT_TRIGGER_NOT_EQUAL_TO, CONTEXT_TRIGGER_DISABLED);
+context_trigger_rule_entry_add_comparison_string(gps_condition, CONTEXT_TRIGGER_STATE, CONTEXT_TRIGGER_NOT_EQUAL_TO, CONTEXT_TRIGGER_DISABLED);
+</pre>
+</li>
+<li>Add the conditions to the rule handle. Note that condition is not mandatory and that a rule can have multiple conditions.
+<pre class="prettyprint">
+context_trigger_rule_add_entry(rule, wifi_condition);
+context_trigger_rule_add_entry(rule, gps_condition);
+</pre>
+</li>
+<li> Free the conditions.
+<pre class="prettyprint">
+context_trigger_rule_entry_destroy(wifi_condition);
+context_trigger_rule_entry_destroy(gps_condition);
+</pre>
+</ol>
+                       </div>
+               </li>
+
+               <li>
+                       <div class="devicespec-tit">
+                               <h2 id="set_action" name="set_action" class="items-tit-h2">Setting an Action</h2>
+                               <span class="fr"><a href="#" class="bt-arr"><em>Hide</em></a></span>
+                       </div>
+                       <div class="devicespec-con">
+<p>An application launching or a notification posting request is set as action, which will be triggered if the rule is satisfied. The below example shows how to register a notification posting request. Note that this API supports the very basic form of notifications only.</p>
+<pre class="prettyprint">
+context_trigger_rule_set_action_notification(rule, "Battery Alert", "Battery is getting low. To save your battery, you'd better turn off WiFi or GPS", NULL, NULL);
+</pre>
+<p>Or the application is able to request application launching. An application launching request is manipulated with app control handle. Please refer to the <a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__APP__CONTROL__MODULE.html">App Control</a> API for more details. Below example shows how to set application launching action for reference.</p>
+<pre class="prettyprint">
+app_control_h app;
+// Create app control handle and set application id, operation, and so on.
+...
+context_trigger_rule_set_action_app_control(rule, app);
+</pre>
+                       </div>
+               </li>
+               <li>
+                       <div class="devicespec-tit">
+                               <h2 id="add_rule" name="add_rule" class="items-tit-h2">Adding a Rule</h2>
+                               <span class="fr"><a href="#" class="bt-arr"><em>Hide</em></a></span>
+                       </div>
+                       <div class="devicespec-con">
+<p>After creating a rule, the rule needs to be registered.</p>
+<ol>
+<li>
+Register the rule with the <span style="font-family: Courier New,Courier,monospace;">context_trigger_add_rule()</span> function, a rule id is acquired.
+<pre class="prettyprint">
+int rule_id;
+context_trigger_add_rule(rule, &rule_id);
+</pre>
+<p>If the application adds the same rule with the previously registered one, the same rule id wil be acquired.</p>
+</li>
+<li>
+From now, the application is able to manage the rule with its rule id. The rule handle resource should be released.
+<pre class="prettyprint">
+context_trigger_destroy(rule);
+</pre>
+</li>
+</ol>
+                       </div>
+               </li>
+
+
+               <li>
+                       <div class="devicespec-tit">
+                               <h2 id="enable_rule" name="enable_rule" class="items-tit-h2">Enabling a Rule</h2>
+                               <span class="fr"><a href="#" class="bt-arr"><em>Hide</em></a></span>
+                       </div>
+                       <div class="devicespec-con">
+<p>To activate the rule, the rule needs to be enabled explicitly with its rule id. Note that a rule only can be managed by the application that has registered the rule.</p>
+<pre class="prettyprint">
+context_trigger_enable_rule(rule_id);
+</pre>
+                       </div>
+               </li>
+               <li>
+                       <div class="devicespec-tit">
+                               <h2 id="disable_rule" name="disable_rule" class="items-tit-h2">Disabling a Rule</h2>
+                               <span class="fr"><a href="#" class="bt-arr"><em>Hide</em></a></span>
+                       </div>
+                       <div class="devicespec-con">
+<p>To deactivate the rule for a while, the rule needs to be disabled with its rule id.</p>
+<pre class="prettyprint">
+context_trigger_disable_rule(rule_id);
+</pre>
+                       </div>
+               </li>
+               <li>
+                       <div class="devicespec-tit">
+                               <h2 id="remove_rule" name="remove_rule" class="items-tit-h2">Removing a Rule</h2>
+                               <span class="fr"><a href="#" class="bt-arr"><em>Hide</em></a></span>
+                       </div>
+                       <div class="devicespec-con">
+<p>The application can delete the rule with the <span style="font-family: Courier New,Courier,monospace;">context_trigger_remove_rule()</span> function if it is no longer needed.</p>
+<pre class="prettyprint">
+context_trigger_remove_rule(rule_id);
+</pre>
+                       </div>
+               </li>
+               <li>
+                       <div class="devicespec-tit">
+                               <h2 id="retrieve_rule" name="retrieve_rule" class="items-tit-h2">Retrieving Rules</h2>
+                               <span class="fr"><a href="#" class="bt-arr"><em>Hide</em></a></span>
+                       </div>
+                       <div class="devicespec-con">
+
+<p>The application can retrieve all the owned rules and manage them. As mentioned, activation, deactivation, removal, and retrieval are only allowed to the owner application. The below example shows how to query its own rule IDs, deactivate enabled rules, and remove all the rules.</p>
+<ol>
+<li>
+<p>Retrieve all the enabled rules registered by this application and deactivate them.</p>
+<pre class="prettyprint">
+int* enabled_rule_ids;
+int enabled_count;
+
+context_trigger_get_own_rule_ids(&amp;enabled_rule_ids, &amp;enabled_count, NULL, NULL);
+
+// Deactivate enabled rules
+int i = 0;
+for (i = 0; i < enabled_count; i++) {
+       context_trigger_disable_rule(enabled_rule_ids[i]);
+}
+</pre>
+<li>Only deactivated rules can be deleted. After deactivating enabled rules as above, retrive all the disabled rules owned by the application to remove them.
+<pre class="prettyprint">
+int* disabled_rule_ids;
+int disabled_count;
+
+context_trigger_get_own_rule_ids(NULL, NULL, &amp;disabled_rule_ids, &amp;disabled_count);
+
+// Remove disabled rules
+for (i = 0; i < disabled_count; i++) {
+       context_trigger_remove_rule(disabled_rule_ids[i]);
+}
+</pre>
+</li>
+<li>Finally, free the memory allocated for the <span style="font-family: Courier New,Courier,monospace;">enabled_rule_ids</span> and <span style="font-family: Courier New,Courier,monospace;">disabled_rule_ids</span>.
+<pre class="prettyprint">
+if (enabled_rule_ids) {
+       free(enabled_rule_ids);
+       enabled_rule_ids = NULL;
+}
+
+if (disabled_rule_ids) {
+       free(disabled_rule_ids);
+       disabled_rule_ids = NULL;
+}
+</pre>
+</li>
+</ol>
+                       </div>
+               </li>
+
+
+</ul>
+</div></div>
+
+<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>