Add Dotnet Alarm Api guide 08/140008/6
authorSukHyung, Kang <shine.kang@samsung.com>
Fri, 21 Jul 2017 09:41:58 +0000 (18:41 +0900)
committerEditor Lionbridge <TizenEditor.SEL@lionbridge.com>
Tue, 25 Jul 2017 05:28:01 +0000 (08:28 +0300)
PS3: Reviewed
PS5: Reviewed again
PS6: Fixed typo

Change-Id: I4ad0e2fd1dff7f3962980665d4ddd4b57e73fe60
Signed-off-by: SukHyung, Kang <shine.kang@samsung.com>
org.tizen.guides/html/dotnet/alarm/alarms_cs.htm [new file with mode: 0644]

diff --git a/org.tizen.guides/html/dotnet/alarm/alarms_cs.htm b/org.tizen.guides/html/dotnet/alarm/alarms_cs.htm
new file mode 100644 (file)
index 0000000..70580d8
--- /dev/null
@@ -0,0 +1,237 @@
+<!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>Alarms</title>
+ </head>
+ <body onload="prettyPrint()" style="overflow: auto;">
+
+ <div id="toc-navigation">
+       <div id="profile">
+               <p><img alt="Mobile C#" src="../../images/mobile_s_cs.png"/> <img alt="TV C#" src="../../images/tv_s_cs.png"/></p>
+       </div>
+
+       <div id="toc_border"><div id="toc">
+               <p class="toc-title">Dependencies</p>
+               <ul class="toc">
+                       <li>Tizen 4.0 and Higher for Mobile and TV</li>
+               </ul>
+               <p class="toc-title">Content</p>
+               <ul class="toc">
+                       <li><a href="#prerequisites">Prerequisites</a></li>
+                       <li><a href="#scenario_1">Setting an Alarm with a Specific Delay</a></li>
+                       <li><a href="#scenario_2">Setting an Alarm for a Specific Date</a></li>
+                       <li><a href="#scenario_3">Setting a Recurring Alarm for a Specific Day of the Week</a></li>
+                       <li><a href="#scenario_4">Listing All Scheduled Alarms and Canceling an Alarm</a></li>
+               </ul>
+               <p class="toc-title">Related Info</p>
+               <ul class="toc">
+                       <li><a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Applications_1_1Alarm.html">Tizen.Applications.Alarm Class</a></li>
+                       <li><a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Applications_1_1AlarmManager.html">Tizen.Applications.AlarmManager Class</a></li>
+               </ul>
+       </div></div>
+</div>
+
+<div id="container"><div id="contents"><div class="content">
+<h1>Alarms</h1>
+
+<p>You can use alarms to launch applications or send user notifications at specific times. The mechanism involved in launching the application is the <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Applications_1_1AppControl.html">Tizen.Applications.AppControl</a> class.</p>
+<p>The <code>Tizen.Applications.AppControl</code> class allows launching an application explicitly, giving its package name, or providing certain criteria that the application must meet. For example, the criteria can include the type of data on which the application must be able to operate. The structure containing the criteria is called an application control.</p>
+
+<p>The main features of the <code>Tizen.Applications.Alarm</code> and <code>Tizen.Applications.AlarmManager</code> classes include:</p>
+ <ul>
+<li>Setting alarms with a specific delay
+<p>You can <a href="#scenario_1">set an alarm to trigger after a specific amount of time</a>.</p></li>
+<li>Setting alarms for specific dates
+<p>You can <a href="#scenario_2">set an alarm for a specific date</a>.</p></li>
+<li>Setting recurring alarms
+<p>You can <a href="#scenario_3">set a recurring alarm</a> to trigger on a specific day or days of the week.</p></li>
+<li>Managing existing alarms
+<p>You can <a href="#scenario_4">list all scheduled alarms and cancel them</a>.</p></li>
+</ul>
+
+<h2 id="prerequisites">Prerequisites</h2>
+<p>To enable your application to use the alarm functionality:</p>
+<ol>
+<li>To use the <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Applications_1_1Alarm.html">Tizen.Applications.Alarm</a> and <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Applications_1_1AlarmManager.html">Tizen.Applications.AlarmManager</a> classes, the application has to request permission by adding the following privileges to the <code>tizen-manifest.xml</code> file:
+<pre class="prettyprint">
+&lt;privileges&gt;
+   &lt;privilege&gt;http://tizen.org/privilege/alarm.get&lt;/privilege&gt;
+   &lt;privilege&gt;http://tizen.org/privilege/alarm.set&lt;/privilege&gt;
+   &lt;!--If an alarm is used to send a notification--&gt;
+   &lt;privilege&gt;http://tizen.org/privilege/notification&lt;/privilege&gt;
+&lt;/privileges&gt;
+</pre>
+</li>
+<li>To use the methods and properties of the <code>Tizen.Applications.Alarm</code> and <code>Tizen.Applications.AlarmManager</code> classes, include the <a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Applications.html">Tizen.Applications</a> namespace in your application:
+<pre class="prettyprint">
+using Tizen.Applications;
+</pre>
+</li>
+<li>To use the methods and properties of the <a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Applications_1_1Notifications.html">Tizen.Applications.Notifications</a> namespace to make an alarm send a notification, include the namespace in your application:
+<pre class="prettyprint">
+using Tizen.Applications.Notifications;
+</pre>
+</li>
+</ol>
+
+<h2 id="scenario_1">Setting an Alarm with a Specific Delay</h2>
+
+<p>You can set an alarm which, when it expires,  either launches an application or sends a notification to the user:</p>
+
+<ul>
+       <li>To set an alarm to launch an application:
+       <p>You need 2 applications: the "AlarmRegister" application that sets the alarm, and the "AlarmTarget" application that is launched when the alarm expires.</p>
+       <ol>
+       <li>In the AlarmRegister application:
+               <ol type="a">
+                       <li>To identify which application to start when the alarm expires, the <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Applications_1_1AlarmManager.html">Tizen.Applications.AlarmManager</a> class needs an application control instance.
+                       <p>Create a new instance of the <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Applications_1_1AppControl.html">Tizen.Applications.AppControl</a> class, and set the <code>Operation</code> and <code>ApplicationID</code> properties for it. The <code>Operation</code> property identifies the operation to be performed, and the <code>ApplicationID</code> property identifies the <code>appid</code> of the target application to be launched. You can get the <code>appid</code> of the target application from its <code>tizen-manifest.xml</code> file.</p>
+<pre class="prettyprint">
+int DELAY = 2;
+int PERIOD = 1;
+
+AppControl appControl = new AppControl();
+
+appControl.Operation = AppControlOperations.Default;
+appControl.ApplicationId = "org.tizen.alarmslave";
+</pre>
+                       </li>
+                       <li>To schedule an alarm after a delay, use the <code>CreateAlarm()</code> method of the <code>Tizen.Applications.AlarmManager</code> class, with the initial delay, interval for subsequent alarms, and instance of the <code>Tizen.Applications.AppControl</code> class as parameters.
+                       <p>The method creates the alarm as a new instance of the <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Applications_1_1Alarm.html">Tizen.Applications.Alarm</a> class.</p>
+<pre class="prettyprint">
+Alarm myAlarm = AlarmManager.CreateAlarm(DELAY, PERIOD, appControl);
+</pre>
+                       </li>
+               </ol>
+</li>
+
+<li>When the alarm expires, it triggers the <code>OnAppControlReceived()</code> event handler in the AlarmTarget application:
+<pre class="prettyprint">
+protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
+{
+    base.OnAppControlReceived(e);
+}
+</pre>
+</li></ol></li>
+
+<li>To set an alarm to send a notification to the user:
+       <ol>
+               <li>Create a notification to be sent to the user as an instance of the <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Applications_1_1Notifications_1_1Notification.html">Tizen.Applications.Notifications.Notification</a> class:
+<pre class="prettyprint">
+int DELAY = 2;
+int PERIOD = 1;
+Notification myNoti;
+
+myNoti = new Notification
+{
+    Title = "Notification",
+    Content = "Hello Tizen"
+};
+</pre>
+               </li>
+               <li>To schedule an alarm after a delay, use the <code>CreateAlarm()</code> method of the <code>Tizen.Applications.AlarmManager</code> class, with the initial delay, interval for subsequent alarms, and instance of the <code>Tizen.Applications.Notifications.Notification</code> class as parameters.
+               <p>The method creates the alarm as a new instance of the <code>Tizen.Applications.Alarm</code> class.</p>
+
+<pre class="prettyprint">
+Alarm myAlarm = AlarmManager.CreateAlarm(DELAY, PERIOD, myNoti);
+</pre>
+</li>
+</ol></li>
+</ul>
+
+<h2 id="scenario_2">Setting an Alarm for a Specific Date</h2>
+
+<p>To schedule an alarm for a specific date, use the <code>CreateAlarm()</code> method of the <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Applications_1_1AlarmManager.html">Tizen.Applications.AlarmManager</a> class with an instance of the <code>DateTime</code> structure as its first parameter.</p>
+<p>The following example schedules an application control to trigger 20 seconds after the current time (using the <code>AddSecond()</code> method of the <code>DateTime</code> structure):</p>
+<pre class="prettyprint">
+DateTime dt = AlarmManager.GetCurrentTime();
+
+myAlarm = AlarmManager.CreateAlarm(dt.AddSeconds(20), appControl);
+</pre>
+
+
+<h2 id="scenario_3">Setting a Recurring Alarm for a Specific Day of the Week</h2>
+
+<p>You can set a recurring alarm that goes off at a specific moment, and thereafter at regular intervals.</p>
+<p>To schedule a recurring alarm to go off on specific days of the week, use the <code>CreateAlarm()</code> method of the <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Applications_1_1AlarmManager.html">Tizen.Applications.AlarmManager</a> class, with values of the <a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Applications.html#aa5dc08f5b768f40072c0e57db5c11b1d">Tizen.Applications.AlarmWeekFlag</a> enumeration as the second parameter. You can join multiple values together to set the alarm to trigger on multiple days of the week.</p>
+<p>The following example schedules an application control to be invoked at a set time every Tuesday and Friday:</p>
+
+<pre class="prettyprint">
+Tizen.Applications.AppControl appControl = new Tizen.Applications.AppControl();
+appControl.Operation = AppControlOperations.Default;
+appControl.ApplicationId = "org.tizen.alarmslave"
+
+Alarm myAlarm = AlarmManager.CreateAlarm(DateTime.New.AddSecond(10),
+                                         AlarmWeekFlag.Tuesday | AlarmWeekFlag.Friday, appControl);
+</pre>
+
+<h2 id="scenario_4">Listing All Scheduled Alarms and Canceling an Alarm</h2>
+
+<p>You can list all scheduled alarms, and cancel alarms either one by one or all at once:</p>
+<ul>
+<li>To list all scheduled alarms, use the <code>GetAllScheduledAlarms()</code> method of the <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Applications_1_1AlarmManager.html">Tizen.Applications.AlarmManager</a> class:
+<pre class="prettyprint">
+List&lt;Alarm&gt; alarms;
+
+alarms = (List&lt;Alarm&gt;)AlarmManager.GetAllScheduledAlarms();
+</pre>
+</li>
+<li>To cancel a single scheduled alarm, use the <code>Cancel()</code> method of the <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Applications_1_1Alarm.html">Tizen.Applications.Alarm</a> class:
+
+<pre class="prettyprint">
+Tizen.Applications.AppControl appControl = new Tizen.Applications.AppControl();
+Alarm myAlarm;
+
+appControl.Operation = AppControlOperations.Default;
+appControl.ApplicationId = "org.tizen.alarmslave";
+myAlarm = AlarmManager.CreateAlarm(100, appControl);
+
+try
+{
+    <span class="highlight">myAlarm.Cancel();</span>
+}
+catch (Exception e)
+{
+    Log.Error("ALARM", "Exception occurs");
+}
+</pre>
+</li>
+<li>To cancel all alarms registered by the application, use the <code>CancelAll()</code> method of the <code>Tizen.Applications.AlarmManager</code> class:
+<pre class="prettyprint">
+AlarmManager.CancelAll();
+</pre>
+</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>