HarmonyOS 新建日程提醒时如何设置提醒

新建日程提醒时如何设置提醒,是否能提供示例?

1.addEvent中是否是设置了reminderTime的数值就可以开启提醒了。

2.看里面是number[]怎么设置分钟麻烦提供下示例日程提醒时间,单位为分钟。填写x分钟,即距开始时间提前x分钟提醒,不填时,默认为不提醒,可为负值。

HarmonyOS
2024-12-20 17:45:14
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Heiang

CalendarManagerTest页面demo,省略了在onWindowStageCreate中创建 getCalendarManager ;

import { GlobalContext } from "../util/GlobalContext"
import calendarManager from '@ohos.calendarManager';
import { BusinessError } from '@kit.BasicServicesKit';

@Entry
@Component
struct CalendarManagerTest {
  @State message: string = 'Hello World';
  private calendarManager:calendarManager.CalendarManager = GlobalContext.getContext().getObject("calendarManager") as calendarManager.CalendarManager

  aboutToAppear(): void {
    this.test()
  }

  test(){
    //创建 calendar 对象
    let calendar: calendarManager.Calendar | undefined = undefined;
    //设置日程时间
    const date = new Date();
    const event: calendarManager.Event = {
      type: calendarManager.EventType.NORMAL,
      startTime: date.getTime() + 5 * 60 * 1000,
      endTime: date.getTime() + 10 * 60 * 1000,
      //[1,3,5]这种设置方式,会在日历中生成五个节点,分别在 startTime 前1分钟,3分钟 ,5分钟三个节点进行提示
      reminderTime: [1,3,5]
    };

    // getCalendar(callback: AsyncCallback<Calendar>): void
    // https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-calendarmanager-0000001813416768#ZH-CN_TOPIC_0000001813416768__getcalendar
    this.calendarManager?.getCalendar().then((data: calendarManager.Calendar) => {
      console.info(`Succeeded to get calendar, data -> ${JSON.stringify(data)}`);
      calendar = data;
      calendar.addEvent(event, (err: BusinessError, data: number): void => {
        if (err) {
          console.error(`Failed to addEvent, err -> ${JSON.stringify(err)}`);
        } else {
          console.info(`Succeeded to add event, id -> ${data}`);
        }
      });
    }).catch((err: BusinessError) => {
      console.error(`Failed to get calendar, err -> ${JSON.stringify(err)}`);
    });
  }

  build() {
    RelativeContainer() {
      Text(this.message)
        .id('CalendarManagerTestHelloWorld')
        .fontSize(50)
        .fontWeight(FontWeight.Bold)
        .alignRules({
          center: { anchor: '__container__', align: VerticalAlign.Center },
          middle: { anchor: '__container__', align: HorizontalAlign.Center }
        })
        .onClick(()=>{
          this.test()
        })
    }
    .height('100%')
    .width('100%')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
分享
微博
QQ
微信
回复
2024-12-20 20:24:19
相关问题
JS如何添加日历日程提醒
8956浏览 • 1回复 待解决
如何设置给消息通知设置提醒方式
2596浏览 • 1回复 待解决
后台代理提醒,定时闹钟提醒功能。
1805浏览 • 1回复 待解决
HarmonyOS 关于代理提醒设置问题
1445浏览 • 1回复 待解决
HarmonyOS 版本升级提醒
1003浏览 • 1回复 待解决
定时提醒功能如何实现?
5976浏览 • 1回复 待解决
HarmonyOS app后台提醒功能
871浏览 • 1回复 待解决
PA开发,如何添加日历提醒
4994浏览 • 1回复 待解决
HarmonyOS 关于代理提醒数量的问题
1326浏览 • 1回复 待解决
ArkTS后台代理提醒,需要如何处理?
2070浏览 • 1回复 待解决
HarmonyOS 9的API废弃IDE有提醒
713浏览 • 1回复 待解决