2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 namespace Tizen.Applications
22 /// The Alarm API allows setting an "alarm clock" for the delivery of a notification at some point in the future.
26 /// public class AlarmExample
29 /// IEnumerable < Alarm > alarms = AlarmManager.GetAllScheduledAlarms();
30 /// alarms[0].Cancel();
36 private const string _logTag = "Tizen.Applications.Alarm";
39 /// Constructor created with new AlarmId.
41 /// <param name="id"></param>
42 internal Alarm(int id)
48 /// The alarm ID uniquely identifies an alarm.
56 /// Gets the recurrence days of the week.
58 /// <privilege>http://tizen.org/privilege/alarm.get</privilege>
60 /// week_flag may be a combination of days, like Tuesday | Friday
62 public AlarmWeekFlag WeekFlag
67 AlarmError ret = (AlarmError)Interop.Alarm.GetAlarmWeekFlag(AlarmId, out week);
68 if (ret != AlarmError.None)
70 Log.Error(_logTag, "Failed to get WeekFlag");
73 return (AlarmWeekFlag)week;
78 /// Gets the scheduled time.
80 /// <privilege>http://tizen.org/privilege/alarm.get</privilege>
81 public DateTime ScheduledDate
85 Interop.Alarm.DateTime value;
86 AlarmError ret = (AlarmError)Interop.Alarm.GetAlarmScheduledDate(AlarmId, out value);
87 if (ret != AlarmError.None)
89 Log.Error(_logTag, "Failed to get WeekFlag");
92 DateTime time = AlarmManager.ConvertIntPtrToDateTime(value);
98 /// Gets the period of time between the recurrent alarms.
100 /// <privilege>http://tizen.org/privilege/alarm.get</privilege>
106 AlarmError ret = (AlarmError)Interop.Alarm.GetAlarmScheduledPeriod(AlarmId, out period);
107 if (ret != AlarmError.None)
109 Log.Error(_logTag, "Failed to get WeekFlag");
117 /// Gets the AppControl to be invoked when the the alarm is triggered.
119 /// <privilege>http://tizen.org/privilege/alarm.get</privilege>
120 public AppControl AlarmAppControl
124 SafeAppControlHandle handle;
125 AlarmError ret = (AlarmError)Interop.Alarm.GetAlarmAppControl(AlarmId, out handle);
127 if (ret != AlarmError.None)
129 Log.Error(_logTag, "Failed to get WeekFlag");
132 return new AppControl(handle);
137 /// Gets whether the alarm will launch global application or not.
139 /// <privilege>http://tizen.org/privilege/alarm.set</privilege>
140 /// <privilege>http://tizen.org/privilege/alarm.get</privilege>
146 AlarmError ret = (AlarmError)Interop.Alarm.GetAlarmGlobalFlag(AlarmId, out global);
147 if (ret != AlarmError.None)
149 Log.Error(_logTag, "Failed to get WeekFlag");
157 AlarmError ret = (AlarmError)Interop.Alarm.SetAlarmGlobalFlag(AlarmId, value);
158 if (ret != AlarmError.None)
160 Log.Error(_logTag, "Failed to get WeekFlag");
166 /// Cancels the the specific alarm.
168 /// <exception cref="ArgumentException">Thrown in case of Invalid parmaeter.</exception>
169 /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied due to insufficient previlleges.</exception>
170 /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
171 /// <privilege>http://tizen.org/privilege/alarm.set</privilege>
174 AlarmError ret = (AlarmError)Interop.Alarm.CancelAlarm(AlarmId);
175 if (ret != AlarmError.None)
177 throw AlarmErrorFactory.GetException(ret, "Failed to Cancel alarm");