• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License"),
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import { AsyncCallback } from './basic';
17import notification from './@ohos.notification';
18import { NotificationSlot } from './notification/notificationSlot';
19
20/**
21 * Providers static methods for managing reminders, including publishing or canceling a reminder.
22 * adding or removing a notification slot, and obtaining or cancelling all reminders of the current application.
23 *
24 * @since 9
25 * @syscap SystemCapability.Notification.ReminderAgent
26 * @import reminderAgentManager from '@ohos.reminderAgentManager';
27 */
28declare namespace reminderAgentManager {
29  /**
30   * Publishes a scheduled reminder.
31   *
32   * @since 9
33   * @syscap SystemCapability.Notification.ReminderAgent
34   * @permission ohos.permission.PUBLISH_AGENT_REMINDER
35   * @param { ReminderRequest } reminderReq - Indicates the reminder instance to publish.
36   * @param { AsyncCallback<number> } callback - Indicates the callback function.
37   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
38   */
39  function publishReminder(reminderReq: ReminderRequest, callback: AsyncCallback<number>): void;
40
41  /**
42   * Publishes a scheduled reminder.
43   *
44   * @since 9
45   * @syscap SystemCapability.Notification.ReminderAgent
46   * @permission ohos.permission.PUBLISH_AGENT_REMINDER
47   * @param { ReminderRequest } reminderReq - Indicates the reminder instance to publish.
48   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
49   * @returns { Promise<number> } The reminder id.
50   */
51  function publishReminder(reminderReq: ReminderRequest): Promise<number>;
52
53  /**
54   * Cancels a reminder.
55   *
56   * @since 9
57   * @syscap SystemCapability.Notification.ReminderAgent
58   * @param { number } reminderId - Indicates the reminder id.
59   * @param { AsyncCallback<void> } callback - Indicates the callback function.
60   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
61   */
62  function cancelReminder(reminderId: number, callback: AsyncCallback<void>): void;
63
64  /**
65   * Cancels a reminder.
66   *
67   * @since 9
68   * @syscap SystemCapability.Notification.ReminderAgent
69   * @param { number } reminderId - Indicates the reminder id.
70   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
71   * @returns { Promise<void> } The promise returned by the function.
72   */
73  function cancelReminder(reminderId: number): Promise<void>;
74
75  /**
76   * Obtains all the valid reminders of current application.
77   *
78   * @since 9
79   * @syscap SystemCapability.Notification.ReminderAgent
80   * @param { AsyncCallback<Array<ReminderRequest>> } callback - Indicates the callback function.
81   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
82   */
83  function getValidReminders(callback: AsyncCallback<Array<ReminderRequest>>): void;
84
85  /**
86   * Obtains all the valid reminders of current application.
87   *
88   * @since 9
89   * @syscap SystemCapability.Notification.ReminderAgent
90   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
91   * @returns { Promise<Array<ReminderRequest>> } The promise returned by the function.
92   */
93  function getValidReminders(): Promise<Array<ReminderRequest>>;
94
95  /**
96   * Cancels all the reminders of current application.
97   *
98   * @since 9
99   * @syscap SystemCapability.Notification.ReminderAgent
100   * @param { AsyncCallback<void> } callback - Indicates the callback function.
101   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
102   */
103  function cancelAllReminders(callback: AsyncCallback<void>): void;
104
105  /**
106   * Cancels all the reminders of current application.
107   *
108   * @since 9
109   * @syscap SystemCapability.Notification.ReminderAgent
110   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
111   * @returns { Promise<void> } The promise returned by the function.
112   */
113  function cancelAllReminders(): Promise<void>;
114
115  /**
116   * Add notification slot.
117   *
118   * @since 9
119   * @syscap SystemCapability.Notification.ReminderAgent
120   * @param { NotificationSlot } slot - Indicates the slot.
121   * @param { AsyncCallback<void> } callback - Indicates the callback function.
122   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
123   */
124  function addNotificationSlot(slot: NotificationSlot, callback: AsyncCallback<void>): void;
125
126  /**
127   * Add notification slot.
128   *
129   * @since 9
130   * @syscap SystemCapability.Notification.ReminderAgent
131   * @param { NotificationSlot } slot - Indicates the slot.
132   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
133   * @returns { Promise<void> } The promise returned by the function.
134   */
135  function addNotificationSlot(slot: NotificationSlot): Promise<void>;
136
137  /**
138   * Deletes a created notification slot based on the slot type.
139   *
140   * @since 9
141   * @syscap SystemCapability.Notification.ReminderAgent
142   * @param { notification.SlotType } slotType Indicates the type of the slot.
143   * @param { AsyncCallback<void> } callback - Indicates the callback function.
144   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
145   */
146  function removeNotificationSlot(slotType: notification.SlotType, callback: AsyncCallback<void>): void;
147
148  /**
149   * Deletes a created notification slot based on the slot type.
150   *
151   * @since 9
152   * @syscap SystemCapability.Notification.ReminderAgent
153   * @param { notification.SlotType } slotType Indicates the type of the slot.
154   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
155   * @returns { Promise<void> } The promise returned by the function.
156   */
157  function removeNotificationSlot(slotType: notification.SlotType): Promise<void>;
158
159  /**
160   * Declares action button type.
161   *
162   * @since 9
163   * @syscap SystemCapability.Notification.ReminderAgent
164   */
165  export enum ActionButtonType {
166    /**
167     * Button for closing the reminder.
168     * @since 9
169     * @syscap SystemCapability.Notification.ReminderAgent
170     */
171    ACTION_BUTTON_TYPE_CLOSE = 0,
172
173    /**
174     * Button for snoozing the reminder.
175     * @since 9
176     * @syscap SystemCapability.Notification.ReminderAgent
177     */
178    ACTION_BUTTON_TYPE_SNOOZE = 1
179  }
180
181  /**
182   * Declares reminder type.
183   *
184   * @since 9
185   * @syscap SystemCapability.Notification.ReminderAgent
186   */
187  export enum ReminderType {
188    /**
189     * Countdown reminder.
190     * @since 9
191     * @syscap SystemCapability.Notification.ReminderAgent
192     */
193    REMINDER_TYPE_TIMER = 0,
194
195    /**
196     * Calendar reminder.
197     * @since 9
198     * @syscap SystemCapability.Notification.ReminderAgent
199     */
200    REMINDER_TYPE_CALENDAR = 1,
201
202    /**
203     * Alarm reminder.
204     * @since 9
205     * @syscap SystemCapability.Notification.ReminderAgent
206     */
207    REMINDER_TYPE_ALARM = 2
208  }
209
210  /**
211   * Action button information. The button will show on displayed reminder.
212   *
213   * @since 9
214   * @syscap SystemCapability.Notification.ReminderAgent
215   */
216  interface ActionButton {
217    /**
218     * Text on the button.
219     * @since 9
220     * @syscap SystemCapability.Notification.ReminderAgent
221     */
222    title: string;
223
224    /**
225     * Button type.
226     * @since 9
227     * @syscap SystemCapability.Notification.ReminderAgent
228     */
229    type: ActionButtonType;
230  }
231
232  /**
233   * Want agent information.
234   * It will switch to target ability when you click the displayed reminder.
235   *
236   * @since 9
237   * @syscap SystemCapability.Notification.ReminderAgent
238   */
239  interface WantAgent {
240    /**
241     * Name of the package redirected to when the reminder notification is clicked.
242     * @since 9
243     * @syscap SystemCapability.Notification.ReminderAgent
244     */
245    pkgName: string;
246
247    /**
248     * Name of the ability that is redirected to when the reminder notification is clicked.
249     * @since 9
250     * @syscap SystemCapability.Notification.ReminderAgent
251     */
252    abilityName: string;
253  }
254
255  /**
256   * Max screen want agent information.
257   *
258   * @since 9
259   * @syscap SystemCapability.Notification.ReminderAgent
260   */
261  interface MaxScreenWantAgent {
262    /**
263     * Name of the package that is automatically started when the reminder arrives and the device is not in use.
264     * @since 9
265     * @syscap SystemCapability.Notification.ReminderAgent
266     */
267    pkgName: string;
268
269    /**
270     * Name of the ability that is automatically started when the reminder arrives and the device is not in use.
271     * @since 9
272     * @syscap SystemCapability.Notification.ReminderAgent
273     */
274    abilityName: string;
275  }
276
277  /**
278   * Reminder Common information.
279   *
280   * @since 9
281   * @syscap SystemCapability.Notification.ReminderAgent
282   */
283  interface ReminderRequest {
284    /**
285     * Type of the reminder.
286     * @since 9
287     * @syscap SystemCapability.Notification.ReminderAgent
288     */
289    reminderType: ReminderType;
290
291    /**
292     * Action button displayed on the reminder notification.
293     * (The parameter is optional. Up to two buttons are supported).
294     * @since 9
295     * @syscap SystemCapability.Notification.ReminderAgent
296     */
297    actionButton?: [ActionButton?, ActionButton?];
298
299    /**
300     * Information about the ability that is redirected to when the notification is clicked.
301     * @since 9
302     * @syscap SystemCapability.Notification.ReminderAgent
303     */
304    wantAgent?: WantAgent;
305
306    /**
307     * Information about the ability that is automatically started when the reminder arrives.
308     * If the device is in use, a notification will be displayed.
309     * @since 9
310     * @syscap SystemCapability.Notification.ReminderAgent
311     */
312    maxScreenWantAgent?: MaxScreenWantAgent;
313
314    /**
315     * Ringing duration.
316     * @since 9
317     * @syscap SystemCapability.Notification.ReminderAgent
318     */
319    ringDuration?: number;
320
321    /**
322     * Number of reminder snooze times.
323     * @since 9
324     * @syscap SystemCapability.Notification.ReminderAgent
325     */
326    snoozeTimes?: number;
327
328    /**
329     * Reminder snooze interval.
330     * @since 9
331     * @syscap SystemCapability.Notification.ReminderAgent
332     */
333    timeInterval?: number;
334
335    /**
336     * Reminder title.
337     * @since 9
338     * @syscap SystemCapability.Notification.ReminderAgent
339     */
340    title?: string;
341
342    /**
343     * Reminder content.
344     * @since 9
345     * @syscap SystemCapability.Notification.ReminderAgent
346     */
347    content?: string;
348
349    /**
350     * Content to be displayed when the reminder is expired.
351     * @since 9
352     * @syscap SystemCapability.Notification.ReminderAgent
353     */
354    expiredContent?: string;
355
356    /**
357     * Content to be displayed when the reminder is snoozing.
358     * @since 9
359     * @syscap SystemCapability.Notification.ReminderAgent
360     */
361    snoozeContent?: string;
362
363    /**
364     * notification id. If there are reminders with the same ID, the later one will overwrite the earlier one.
365     * @since 9
366     * @syscap SystemCapability.Notification.ReminderAgent
367     */
368    notificationId?: number;
369
370    /**
371     * Type of the slot used by the reminder.
372     * @since 9
373     * @syscap SystemCapability.Notification.ReminderAgent
374     */
375    slotType?: notification.SlotType;
376  }
377
378  interface ReminderRequestCalendar extends ReminderRequest {
379    /**
380     * Reminder time.
381     * @since 9
382     * @syscap SystemCapability.Notification.ReminderAgent
383     */
384    dateTime: LocalDateTime;
385
386    /**
387     * Month in which the reminder repeats.
388     * @since 9
389     * @syscap SystemCapability.Notification.ReminderAgent
390     */
391    repeatMonths?: Array<number>;
392
393    /**
394     * Date on which the reminder repeats.
395     * @since 9
396     * @syscap SystemCapability.Notification.ReminderAgent
397     */
398    repeatDays?: Array<number>;
399  }
400
401  /**
402   * Alarm reminder information.
403   *
404   * @since 9
405   * @syscap SystemCapability.Notification.ReminderAgent
406   */
407  interface ReminderRequestAlarm extends ReminderRequest {
408    /**
409     * Hour portion of the reminder time.
410     * @since 9
411     * @syscap SystemCapability.Notification.ReminderAgent
412     */
413    hour: number;
414
415    /**
416     * minute portion of the reminder time.
417     * @since 9
418     * @syscap SystemCapability.Notification.ReminderAgent
419     */
420    minute: number;
421
422    /**
423     * Days of a week when the reminder repeates.
424     * @since 9
425     * @syscap SystemCapability.Notification.ReminderAgent
426     */
427    daysOfWeek?: Array<number>;
428  }
429
430  /**
431   * CountDown reminder information.
432   *
433   * @since 9
434   * @syscap SystemCapability.Notification.ReminderAgent
435   */
436  interface ReminderRequestTimer extends ReminderRequest {
437    triggerTimeInSeconds: number;
438  }
439
440  interface LocalDateTime {
441    /**
442     * value of year.
443     * @since 9
444     * @syscap SystemCapability.Notification.ReminderAgent
445     */
446    year: number;
447
448    /**
449     * value of month.
450     * @since 9
451     * @syscap SystemCapability.Notification.ReminderAgent
452     */
453    month: number;
454
455    /**
456     * value of day.
457     * @since 9
458     * @syscap SystemCapability.Notification.ReminderAgent
459     */
460    day: number;
461
462    /**
463     * value of hour.
464     * @since 9
465     * @syscap SystemCapability.Notification.ReminderAgent
466     */
467    hour: number;
468
469    /**
470     * value of minute.
471     * @since 9
472     * @syscap SystemCapability.Notification.ReminderAgent
473     */
474    minute: number;
475
476    /**
477     * value of second.
478     * @since 9
479     * @syscap SystemCapability.Notification.ReminderAgent
480     */
481    second?: number;
482  }
483}
484export default reminderAgentManager;
485